open(T,"<$ARGV[0]"); my (@data,$count); foreach((@data = <T>)){++$count;(/$ARGV[1]/)?eval{print;for(1..$ARGV[2 +]){print $data[$count] if defined $data[++$count];};exit()} : undef;} close(T);
one two thrtestee four five six werwr werwer seen?
# perl -w script.pl datafile pattern numlines perl -w script.pl data.dat test 4
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Reading a pattern and a number of lines after it
by blakem (Monsignor) on Jan 09, 2002 at 04:45 UTC | |
by simon.proctor (Vicar) on Jan 09, 2002 at 05:13 UTC | |
|
Re: Reading a pattern and a number of lines after it
by jryan (Vicar) on Jan 09, 2002 at 05:39 UTC | |
by tilly (Archbishop) on Jan 09, 2002 at 06:25 UTC | |
by jryan (Vicar) on Jan 09, 2002 at 06:37 UTC | |
|
Re: Reading a pattern and a number of lines after it
by Juerd (Abbot) on Jan 09, 2002 at 07:03 UTC |