in reply to Parsing a Log file

Two things:

1. Please preview your question before you post it. The contents of your log file would be a lot easier to read if it was in a <pre> ... </pre> block. Update: Thanks for reformatting it.

2. What information do you want to extract from the log file? We need to know this in order to help you. Update: Okay, now I see what you want to parse.

Here's one way of doing it:

my $r; while (<>) { if (/^Current software package status is: *(.*)/) { $r->{package_status} = $1; } elsif (/^(WORKSTATION\d+):/) { $r->{workstation} = $1; $r->{workstation_line} = $. } elsif (/^(User program exit code: .*)/) { $r->{exit_message} = $1; $r->{exit_line} = $. # process $r if ($r->{package_status} eq "IC--E") { print "$r->{workstation}(line $r->{workstation_line}) $r->{exit_ +message}(line $r->{exit_line}) } $r = {}; # clear variables for next record } }
This assume that package status line precedes workstation line which precedes the exit message line.

Replies are listed 'Best First'.
Re^2: Parsing a Log file
by polettix (Vicar) on Dec 16, 2007 at 22:42 UTC
    The contents of your log file would be a lot easier to read if it was in a <pre> ... </pre> block.
    While nobody can deny this, it's usually better to suggest <code>...</code> (or shorter <c>...</c>) blocks for formatting code, file contents, printouts from shell sessions, etc. In the first two cases, in particular, this eases the other monks with stuff like downloading the fragment.

    Hey! Up to Dec 16, 2007 I was named frodo72 here, take note of the change! Flavio
    perl -ple'$_=reverse' <<<ti.xittelop@oivalf

    Io ho capito... ma tu che hai detto?
      On the contrary, I can deny it. To quote the bottom of the preview page:

      If you think you're going to use <pre> tags — don't! Use <code> tags instead! This applies to data as well as code.

      Aside from downloadability, using <code> instead of <pre> also prevents long lines from messing up page formatting.