in reply to Re: Buffered read and matching
in thread Buffered read and matching

Right, I wanted to suggest some state machine along this too:

#!/usr/bin/perl use strict; my @lines; sub flush { return unless grep(/'Errors'/, @_); print "Got:\n\t", join ("\t", @_), "\n"; } while (<>) { # trigger on last line of an error message flush(@lines,$_),@lines=(),next if m{^\s*\};\s*$}; # triggger on next timestamp flush(@lines), @lines=() if m{^\s*\[\d\d\d\d\/}; push(@lines, $_); } flush(@lines);
However, all solutions I have seen so far trigger evaluation with the next timestamp only. When using tail -f, the error will be processed only when the next log-line with a time-stamp is encountered - which might happen some hours or days later. IF seeing an error ASAP is important to the OP, the evaluation should be triggered additionally by matching for }; or by some timeout-mechanism, e.g. using alarm().
Update: final flush(...) added

Replies are listed 'Best First'.
Re^3: Buffered read and matching
by jethro (Monsignor) on Oct 15, 2008 at 13:41 UTC
    You might have been mislead by a bug in my solution where I used the wrong bracket for end of error detection (which makes the script not work at all), but it does process the error when ] is encountered, i.e. well before the next log-line.