in reply to get n lines before or after a pattern
The another advantage of this approach compared to other way is you won't lose the rest part of every chunk. you can print any elements of @vals by changing slice.use List::MoreUtils qw/natatime/; my @contents = <DATA>; pop @contents; shift @contents; my $it = natatime 8, @contents; while (my @vals = $it->()) { print "@vals[0,1,2] \n" if $vals[2] =~ /jack/; } __DATA__ start id 10 address Richmond name jack xxxxx aaaaa lastname black yyyy zzzzz id 11 address Central name rick cccccc dddddd lastname hanna eeeee yyyyy id 12 address denver name jack sssss tttttt lastname strong rrrrr mmmmm id 13 address Virginia name mick aaaaaaa ooooooo lastname jagger gggggg hhhhhh id 14 address Maine name rick sssss sssss lastname stewart ssssss ffffff end
I am trying to improve my English skills, if you see a mistake please feel free to reply or /msg me a correction
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: get n lines before or after a pattern
by Kenosis (Priest) on Jul 25, 2012 at 19:06 UTC | |
|
Re^2: get n lines before or after a pattern
by ww (Archbishop) on Jul 25, 2012 at 20:59 UTC | |
by Kenosis (Priest) on Jul 25, 2012 at 21:32 UTC | |
by ww (Archbishop) on Jul 25, 2012 at 22:14 UTC | |
by Kenosis (Priest) on Jul 25, 2012 at 22:31 UTC |