blob: 0acb7738657f5d3fc4207af31f0b00de69f338b9 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
|
From nstn.ns.ca!news.cs.indiana.edu!news.nd.edu!spool.mu.edu!uunet!elroy.jpl.nasa.gov!swrinde!zaphod.mps.ohio-state.edu!uakari.primate.wisc.edu!dali.cs.montana.edu!milton!uw-beaver!fluke!ssc-vax!brennan Mon May 6 23:41:40 ADT 1991
Article: 26492 of comp.unix.questions
Path: cs.dal.ca!nstn.ns.ca!news.cs.indiana.edu!news.nd.edu!spool.mu.edu!uunet!elroy.jpl.nasa.gov!swrinde!zaphod.mps.ohio-state.edu!uakari.primate.wisc.edu!dali.cs.montana.edu!milton!uw-beaver!fluke!ssc-vax!brennan
From: brennan@ssc-vax.UUCP (Michael D Brennan)
Newsgroups: comp.unix.questions
Subject: Re: How to print last <n> pages of a file
Message-ID: <3948@ssc-bee.ssc-vax.UUCP>
Date: 6 May 91 15:42:00 GMT
Article-I.D.: ssc-bee.3948
Organization: Boeing Aerospace & Electronics, Seattle WA
Lines: 33
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]
}
END {
i = NR - numpages + 1
if ( i <= 0 ) i = 1
while( i <= NR ) print page[i++]
}'
case $# in
0) awk "$program" numpages=1 - ;;
1) awk "$program" numpages=$1 - ;;
*) pages=$1 ; shift
awk "$program" numpages=$pages $* ;;
esac
|