in reply to grab 'n' lines from a file above and below a /match/

untested. On unix grep can do exactly this.
my $MAX = 5; local $_; OUT: while ( defined ( $_ = <LOG> ) ){ push @lines, $_; shift @lines if @lines > $MAX; if ( /bla bla/ ) { print @lines, $_; for ( 1 .. $MAX ) { last OUT unless defined ( $_ = <LOG> ); print; } } }
Boris

Replies are listed 'Best First'.
Re^2: grab 'n' lines from a file above and below a /match/
by barathbr (Scribe) on Sep 16, 2004 at 23:11 UTC
    Thanks a ton Boris :) works as advertised !!!