[Sderby] PERL again!

sderby@mailman.lug.org.uk sderby at mailman.lug.org.uk
Fri Jan 10 09:13:01 2003


Mike

Here is a script that searches a file called "drw_pc4.dat" for a string
containing  the text "Application exception occurred:.*?exe". Are you
familiar with regular expressions ? The bit that does the work is the line:

/(Application exception occurred:.*?exe)/so;

and any successful matches are put in $1. This script merely reports the
number of incidents to the stdout but you could print the actual string to a
log file everytime it found a match.

If you need any futher help let me know.

Andre

script below
*****************************************
#!/usr/bin/perl -w
#use strict;
use IO::Handle;

$earlier=time;
open  WATSONFILE,  "< drw_pc4.dat" or die "Cannot open drw_pc4.dat: $!";

while (<WATSONFILE>) {
    /(Application exception occurred:.*?exe)/so;# match multiline dot
includes new line
    $count++;
    if ($1) {
        print "\n matched <<$1>> \n";
    }

}
    $later= time;
    $seconds= $later-$earlier;
    print "\n parsed $count lines in $seconds seconds \n";
close  WATSONFILE;

----- Original Message -----
From: "Mini Mike" <hemstock@tiscali.co.uk>
To: <sderby@mailman.lug.org.uk>
Sent: Thursday, January 09, 2003 5:09 PM
Subject: [Sderby] PERL again!


> Hi all,
>
> I'm currently writing a PERL script to analyse log files from Legarto
backup
> server.  What I want to do is find the failures, which are idenified by a
> line with "Unsuccessful save sets" then a blankish line, then the fialures
> then another blank line.  What I'm thinking of doing if none has a better
> idea is searching for "unsuccessful save sets" finding the line number and
> the adding one and extracting a line at a time for analysis until a blank
> line, what I need to find out how to do is how to find the line number of
the
> line and how to extract lines given their number.
>
> Thanks,
> Mike.
>
> _______________________________________________
> Sderby mailing list
> Sderby@mailman.lug.org.uk
> http://mailman.lug.org.uk/mailman/listinfo/sderby
> Web site: http://sderby.lug.org.uk/
> wiki: http://www.sderby.lug.org.uk/cgi-bin/wiki.pl
>