in reply to Reading a pattern and a number of lines after it
Shenanagians! I call Shenanagians! blakem broke the rules ;)
The original stipulations stated that the arguments would be supplied via command line; here is the shortest I came up with with that:
open(T,"$ARGV[0]"); foreach(@_=<T>){/$ARGV[1]/?print@_[$c..$ARGV[2+$c],exit:$c++} close(T)
Unfortunately, much space is taken up by the $ARGV. Also, note that by changing the exit to a "\n" (or removing it completely) will cause the code will print $ARGV[2] lines for ALL matches. Leaving the exit causes only the first batch to print.
Update:
I can cheat too (using blakem's arguments as an example):
and completely floor him; but, as I said, that would be cheating ;)perl -ne "print((<>)[0..3])if/ou/" test.txt
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re (tilly) 2: Reading a pattern and a number of lines after it
by tilly (Archbishop) on Jan 09, 2002 at 06:25 UTC | |
by jryan (Vicar) on Jan 09, 2002 at 06:37 UTC |