hemanthc has asked for the wisdom of the Perl Monks concerning the following question:

I am trying to extract parts of a text log file. The format is kind of fixed, I can always write code to retrieve the important parts, but I am trying to look for a generic way - or a framework that already does this.

I am looking for something simple and lightweight.

In case the requirement is not clear, the log file has a format like:

my_header (.*) ... time: (.*) ... [error: (.*)] ... status: (.*) ... end_signature

Basically, this contains some lines that may be matched (those enclosed in []s) and some lines that must be matched (those not). Also, it would be interesting if there is a way to specify that the some line need not be at any given location.

If anyone has any pointers on how I can achieve this, I would really appreciate it.

Thanking you in advance,
Hemanth

Replies are listed 'Best First'.
Re: Log File Extracter
by jdporter (Paladin) on Jul 24, 2007 at 20:05 UTC

    Is there any reason the following wouldn't work?

    my( $header, $time, $error, $status ); while (<>) { /my_header (.*)/ and $header = $1; /time: (.*)/ and $time = $1; /error: (.*)/ and $error = $1; /status: (.*)/ and $status = $1; } $header && $time && $status or die "Error: missing one or more of header, time, status\n";

    This is completely flexible with regard to line order, and doesn't even check for the presence of the footer line.

    PS - btw - Please don't repost, unless instructed to do so. Posts can be moved. TIA.

    A word spoken in Mind will reach its own level, in the objective world, by its own weight
Re: Log File Extracter
by hemanthc (Initiate) on Jul 24, 2007 at 13:12 UTC
    ok - I saw the part about "wrong section" a little too late. Will post to "Seekers of Perl Wisdom"