in reply to Re: Re: last $n lines that match a criteria
in thread last $n lines that match a criteria
Here is the progression of code that I took it from (note this is for tail and not the last $n matching lines but the change is minor).
# tail perl -ne '$i=$.%5; $a[$i]=$_; END{print @a[$i+1..$#a,0..$i]}' file perl -ne 'END{print@a[$i+1..$#a,0..$i]}$a[$i=$.%5]=$_' file perl -ne 'END{print@a[$i+1..@a,0..$i]}$a[$i=$.%5]=$_' file perl -pe '$a[$i=$.%5]=$_}{print@a[$i+1..@a,0..$i]' file perl -pe '$_[$==$.%5]=$_}{print@_[$=+1..@_,0..$=]' file
Also, I left out -w on purpose for cases where there were less matches than $n. Try this:
echo foo | perl -wpe 'your code here' file
That is also why I was able to get away with @a.
--
John.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Re: Re: last $n lines that match a criteria
by ysth (Canon) on Nov 17, 2003 at 11:56 UTC |