my $N = ...; # Number of lines before matching line. my $PATTERN = "..."; # What you want to match. my @buffer; while (my $line = <>) { if (@buffer < $N) { push @buffer, $line; next; } if ($line =~ /$PATTERN/) { print $buffer[0]; } shift @buffer; push @buffer, $line; }
In reply to Re: find a match and pull nth line before the match
by JavaFan
in thread find a match and pull nth line before the match
by msensay
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |