How to print last <n> pages of a file

How to print last <n> pages of a file

Post by Michael D Brenn » Wed, 08 May 1991 00:42:00



The following shell & (new) awk program prints the last n pages.

If you get more than 65 lines to a page, the program that inserts
the ^L's should be fixed.

-------------------------------------------------------------
#!/bin/sh
# usage: lastpages   --  prints 1 page reads stdin
#        lastpages  n -- prints  n pages reads stdin
#        lastpages  n  files -- prints n pages, reads file list

program='BEGIN{RS = ORS = "\f" }

{ page[NR] = $0
  if ( NR > numpages )  delete  page[NR-numpages]

Quote:}

END {
  i = NR - numpages + 1
  if ( i <= 0 ) i = 1

  while( i <= NR )  print page[i++]

Quote:}'

case $# in
0)  awk "$program" numpages=1 - ;;
1)  awk "$program" numpages=$1 - ;;
*)  pages=$1 ; shift
    awk "$program" numpages=$pages  $* ;;
esac
 
 
 

1. How to print last <n> pages of a file?

How can I print the last <n> pages of a text file?  Said file has form
feeds at random places, so "tail -132 file | lpr" won't work.  Now, I tried
"pr file | tail -132" but that includes the 5-line headers and footers
that I don't want and don't get with "lpr file".  So I tried
"pr -t file | tail -132" but the -t option turns off page filling so the
form feeds aren't expanded :-(.

Any suggestions?  SunOS 4.1 over here.

--
This is news.  This is your       |    Peter Scott, NASA/JPL/Caltech

2. Which SCSI Adapters are Recognised .?

3. I need a example of X .twmrc file PLEASE <<<<<<<<<<<<<<<<<<<<<

4. Put modules into linear mapping

5. Latest 1.<even>.<n>

6. can't "configure" Karpski

7. <<<<<soundconfig problem <<<<<<<

8. A fw questions from an eager beginner

9. How to print from last page to first page?

10. SOLARIS 2.3 NOT getting the NAMESERVER <<<<<<<<<<<<<<<<<<<<

11. not printing last page of long print outs.

12. Script for makeing whole bunch of account of sol. 2.3 <<<<<<<<<<<<<<<<<

13. CDE <<<<<<<<<-------------- Need Help !