Title: Message
The suggested code does find every instance of the pid at the beginning of a line after the first instance (barring any typos).  With the advantage of a sample source file, I'd tidy the code up this way:
 
        $pid = '';
        while (<DRWTSN>) {   
            if (($pid) = /^\s*App:.+pid=(\d+)/) {
                print  "<b>$_</b><br>";
                next;
            }
            if ($pid ne '' and /^\s*$pid\s/) {
                print "$_<br>";
                next;
            }
            if (/^\s*When:/) {
                print "$_<br>";
                next;
            }
            if (/^\s*Exception\s+number:/) {
                print "$_<br><br><br>";
            }
          }  
The $pid variable is initialized to a null string.  When the first if statement matches, the regex captures the pid string (e.g., ($pid) = /.+pid=(\d+)/) and stores it in the $pid variable.
 
When the $pid variable is non-null, the second if statement uses a regex that includes the $pid variable.
 
Colons aren't special in regexes and don't need to be quoted.  \S means the opposite of \s.  I've also added some beginning of line anchors to minimize unnecessary searching.
 
This routine is not going to print the results in exactly the order you specified.  In order to do that, you're going to have to capture all the interesting lines in their own variables, and then print them in the desired order outside of the while loop.
 
Gary
 
-----Original Message-----
From: Nikko Odiseos [mailto:[EMAIL PROTECTED]]
Sent: Monday, December 03, 2001 12:25 PM
To: Gary MacDonald; [EMAIL PROTECTED]
Subject: RE: Parsing pids from drwtsn.log

Thanks Gary, but that is only half the battle.  The main obstacle is finding the next instance of the $pid after the current one.  I.e. given the following piece of log:
 
Application exception occurred:
        App: netsc_us.exe (pid=69332)
        When: 10/12/2001 @ 13:26:36.172
        Exception number: c0000005 (access violation)
 
*----> System Information <----*
        Computer Name: NODISEOSL2K
......
*----> Task List <----*
   0 Idle.exe
   8 System.exe
 176 SMSS.exe
69332 netscape.exe
2316 talkback.exe
69424 DRWTSN32.exe
   0 _Total.exe
 
Then I want to print out this:
 
App: netsc_us.exe (pid=69332)
        69332 netscape.exe
        When: 10/12/2001 @ 13:26:36.172

      Exception number: c0000005 (access violation)
 
and do this each time I match the string "App: " in the log.
 
Thanks for your help!
 
Nikko
********************************************
Interwoven, Inc.
Moving Business to the Web

Nikko Odiseos
Technical Support Engineer
Direct Line: (408)530-7175
Main Line: (408) 774-2000
Email: [EMAIL PROTECTED]
Web: http://www.interwoven.com
-----Original Message-----
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]]On Behalf Of Gary MacDonald
Sent: Monday, December 03, 2001 10:56 AM
To: [EMAIL PROTECTED]
Subject: RE: Parsing pids from drwtsn.log

I've removed the unnecessary foreach loop and the $line variable.  I'm assuming that 2152 OUTLOOK.exe is at the beginning of a line.
 
The trick is to use the capturing capability of the regex.
 
        $pid = '00000';  # invalid PID
        while (<DRWTSN>) {   
            if (($pid) = /App\:.+pid=(\d+)/) {
                print  "<b>$_</b><br>";
            }
            if (/^$pid\s/) {
                print "$_<br>";
            }
            if (/When\:/) {
                print "$_<br>";
            }
            if (/Exception\Snumber\:/) {
                print "$_<br><br><br>";
            }
          }  
Gary
-----Original Message-----
From: Nikko Odiseos [mailto:[EMAIL PROTECTED]]
Sent: Monday, December 03, 2001 11:33 AM
To: [EMAIL PROTECTED]
Subject: Parsing pids from drwtsn.log

I am trying to parse the dr watson log and trying to get it so that when it fines the pid that generated an exception it looks from that place in the log and looks for the next instance of the pid string and prints it out. 
 
Right now it prints out this:
App: mmc.exe (pid=2152)
When: 11/28/2001 @ 11:42:46.513
 
But I want it to print out this:
App: mmc.exe (pid=2152)
2152 OUTLOOK.exe
When: 11/28/2001 @ 11:42:46.513
 
What I have so far is this:
 
$drwt = "C:/Documents and Settings/All Users.WINNT/Documents/DrWatson/drwtsn32.log";
print  "<a name=\"drwatson\"></a><br>";
print   "<b>Dr Watson Log</b><br>";
if (-e $drwt) {
     open (DRWTSN, $drwt) ;
        while (<DRWTSN>) {   
        foreach $line (<DRWTSN>) {
               if ($line =~ /App\:/) {
               print  "<b>$line</b><br>";
               }
               if ($line =~ /When\:/) {
                print "$line<br>";
               }
               if ($line =~ /Exception\Snumber\:/) {
                print "$line<br><br><br>";
               }
          }  

 close DRWTSN;
 }
else {
print  "No Dr Watson Log in All Users.WINNT\Documents\DrWatson";
}
Thanks for any help!

Reply via email to