#!/usr/bin/perl use strict; my @file = <DATA>; for my $i (0 .. $#file) { if ( $file[$i] =~ /pattern/ ) { print "$file[$_]" for ($i-3 .. $i-1); } } __DATA__ log info line yada yada 0 log info line yada yada 1 log info line yada yada 2 log info line yada yada 3 log info line (pattern) 4 log info line yada yada 5
In reply to Re: How can I print three lines before pattern match?
by bichonfrise74
in thread How can I print three lines before pattern match?
by neurotoxx
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |