in reply to Re: Print line from file only once even if occurrence of pattern is more than once in the line
in thread Print line from file only once even if occurrence of pattern is more than once in the line
my @log_patterns = ( qr/ERROR/, qr/Error/, qr/FATAL/i, qr/critical/i, ); my @log_lines=<$read_tmp_log>; my $i; my $j; for (@log_patterns){ for $i (0..$#log_lines) { next unless $log_lines[$i] =~ $_; my $a = $i - 5 < 0 ? 0 : $i - 5;; my $b = $i + 5 > $#log_lines ? $#log_lines : $i + 5; print $output_file "\n"; for $j($a..$b){ print $output_file $log_lines[$j]; } } }
|
|---|