in reply to (jeffa) Re: when reading a file how to print a line one above the current line??
in thread when reading a file how to print a line one above the current line??
in which case, it'll be handy to have the file name(s) included in the output (I haven't tested this):ls *.log | show-the-alarms
That might not be what the questioner had in mind, but it's a reasonable approach.while ( $file = <>) { chomp $file; my $status = "open file"; open( MYFILE, $file ) or next; $status = 0; my $last = ""; while (<MYFILE>) { if(/ALARM:/) { print "$file:", $. - 1, ": $last"; print "$file:$.: $_"; $status++; } $last = $_; } close MYFILE; } continue { print "Done with $file : found $status error(s)\n"; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: when reading a file how to print a line one above the current line??
by Aristotle (Chancellor) on Jun 04, 2002 at 11:50 UTC |