Problem with perl pattern for date

Hello Friends,

I have been struck with a perl script for quite some time now. I have a log file which gives a date which is sometimes coming in this format

Script /opt/OV/bin/OpC/agtinstall/inst.sh invoked by root at 02/25/11 15:12:50

or sometimes in this format

Script /opt/OV/bin/OpC/agtinstall/inst.sh invoked by root at 02/25/11 
15:12:50

where the date is going to the 2nd line.

I am able to do a search for the first pattern like this

 
if($_ =~ /invoked by root at (\d+)\/(\d+)\/(\d+)[\s|\r|\n](\d+):(\d+):(\d+){1}/)

Pls help me out what to do if the pattern is in the 2nd format.

$
$ cat -n logfile
     1  this is the first line
     2  this is the second line
     3  Script /opt/OV/bin/OpC/agtinstall/inst.sh invoked by root at 02/25/11 15:12:50
     4  this is the fourth line
     5  Script /opt/OV/bin/OpC/agtinstall/inst.sh invoked by root at 02/26/11
     6  21:45:39
     7  this is the seventh line
$
$
$ perl -lne 'BEGIN {undef $/} print $1 while (/\n(Script.*?invoked by root at (\d+)\/(\d+)\/(\d+).*?(\d+):(\d+):(\d+))/msg)' logfile
Script /opt/OV/bin/OpC/agtinstall/inst.sh invoked by root at 02/25/11 15:12:50
Script /opt/OV/bin/OpC/agtinstall/inst.sh invoked by root at 02/26/11
21:45:39
$
$

tyler_durden

The code doesnt seem to work. Actually i have another similar pattern at the bottom of the fiole which is this format

HPOM maintenance summary: 02/26/11 15:39:58. So this search pattern which u specified is matching this one instead of the first one which i specified .

---------- Post updated at 08:37 PM ---------- Previous update was at 02:36 AM ----------

I have made the breakthroufg. here is the code snippet

open(INFILE,"install.log")|| die("File not found");

while($line = <INFILE>)

{
    if ($line =~ /((\d+)\/(\d+)\/(\d+))\Z/g)
    
    {
        $match = $&;
        
        $nextline = <INFILE>;
        
        
        $start="$match$nextline";

        if($start =~ /(\d+)\/(\d+)\/(\d+)\s+(\d+):(\d+)(\d+)/)
        {
            print $4,"\n";
        }
    } # end if  if
    
    elsif ($line =~ /invoked by root at ((\d+)\/(\d+)\/(\d+))\s+(\d+):(\d+):(\d+)\Z/)
    
    {
        print  $&;
    }
 } # //end if while