in reply to last $n lines that match a criteria
perl -ne '$a[($i+=1)%=5] = $_ if /foo/; END{print @a[$i+1..@a,0..$ +i]}' file
This reads all the way through the file so it will be less efficient than methods that read backwards through the file.
--
John.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: last $n lines that match a criteria
by ysth (Canon) on Nov 17, 2003 at 11:19 UTC | |
by jmcnamara (Monsignor) on Nov 17, 2003 at 11:50 UTC | |
by ysth (Canon) on Nov 17, 2003 at 11:56 UTC |