SUMMARY: Print from <line no> to <line no>

From: Steve Madden (smadden@CSU.edu.au)
Date: Wed Jun 12 1996 - 18:39:34 CDT


Thankyou for all the quick replies,

==================
Original Question:
==================

"Payroll printing, something goes wrong and paymaster calls....usual story.
I have to then edit the file to delete unwanted portions of massive file
and print the remainder.

Best solution, would be to stop it happening in the first place.

Second, I was going to write a script to extract records from one <staff
no> to another <staff no> and then print the result.

Does anybody have any better ideas? there has to be a better way.."

=========================================
Reply Thankyous go to (order of arrival)
=========================================
        Peter Allan <peter.allan@aeat.co.uk>
        Wis Macomson <wis@sequent.com>
         Hal Stern <stern@sunrise.East.Sun.COM>
        Alan Hill <ahill@lanser.net>

=============================
 ** BEST RESPONSE by Pete **
=============================

This is easy in sed(1v).
:
#
# to display selected lines of a text file
#
if [ $# != 3 ];
then
   echo "usage: $0 filename first_line_to_display last_line_to_display"
   echo "eg: $0 /etc/hosts 100 110"
   echo " Or use search strings between / characters"
   echo " eg: $0 /etc/hosts /clare/ /harry/"
   exit 1
fi
sed -n "$2,$3p" $1

=====================
 General Responses
=====================

Hal Stern suggested;
 
       sed -n -e '456,987p' filename (for line numbers) OR
      
       fgrep -n "Mr. Big" filename
       fgrep -n "Mrs. Last" filename (Very politically correct :)

Alan Hill suggested;

       From a file of 100 records, I want to print from 23 to 65
           
       tail -78 bigfile | head -43 | lp

       take the last 78 records, ( 100total minus 23 = 77 + 1 )
       pipe and take first 43 records, ( 65 minus 23 = 42 + 1 )
       pipe that to the printer.
       This will print records 23, 24, 25, .... 65.
                        
        (note: Alan's allows for page header adjustment by altering the numbers)

Wis Macomson suggested;

       If my data looks like this:
   
        <staff_no_n> <data for staff_no_n all on one line>
        <staff_no_n+1> <data for staff_no_n+1 all on one line>
        <staff_no_n+2> <data for staff_no_n+2 all on one line>
        <etc>
 
       Assuming <staff_no_n> is an ASCII text string, then do this:

        sed -n -e '/STARTING_staff_no/,/ENDING_staff_no/ p' < payroll_file

==============
 Conclusion
==============

    I think I will have to use a combination of these as the first one by Pete
    solves my payroll problem, but I have found (from the boss) that the users
    have to be able to use it, for any document, so the median value to go on
    will have to be pages (i.e from page 23067 to 69048). As they are all
    formatted differently (to top of page etc). So I will see how I go.

THANKYOU ALL....

Steve..



This archive was generated by hypermail 2.1.2 : Fri Sep 28 2001 - 23:11:01 CDT