Perl to Search through next lines

I have log file that I need to extract time difference occurance when two events happend, between first occurance of TV and when W_NO happend. also read the value=, below example...I can only read the next line but not able to seach all the next lines untill i see W_NO..

Thanks for your help.
Bataf

11/03/2009 07:28:27 TV
11/03/2009 07:28:35 TV
11/03/2009 07:28:37
11/03/2009 07:38:30
11/03/2009 07:39:00 W_NO value="A00005FF.rf"
11/03/2009 07:40:40 TV
11/03/2009 07:40:40
11/03/2009 07:40:42
11/03/2009 07:40:44 W_NO value="A00008FF.rf"
11/03/2009 07:42:57
11/03/2009 07:45:08
11/03/2009 07:45:08 W_NO value="A0058FF.rf"
11/03/2009 07:45:10
11/03/2009 07:45:12
11/03/2009 07:51:47 TV
11/03/2009 07:53:37
11/03/2009 07:53:38
11/03/2009 07:53:38 W_NO value="A070058FF.rf"
11/03/2009 07:55:49
11/03/2009 07:55:49
11/03/2009 07:57:59 W_NO value="A00008FF.rf"
11/03/2009 07:57:59
11/03/2009 08:00:10 TV
11/03/2009 08:00:10 W_NO value="A077758FF.rf"
11/03/2009 08:02:20

 
while( $line = <FILE>){
 chomp ($line);
  my ($fdate,undef)= split(" ",$line);
 #print "$fdate $cdate\n";
 if ($fdate =~ /$curr_date/  && $line =~ m/TV)  {
  $tv++;
  #$nextline = <FILE>;
  my $next =<FILE>;
  
  if ($next =~ m/W_NO/){
   print "$next\n";
   $line = $next
   
   }
  }
use Date::Calc qw/Delta_YMDHMS/;

open my $fh , '<' ,"abc.txt" || die "$!";

my ($start_date,$start_time,$end_date,$end_time);
while(<$fh>) {
        chomp;
        if ($start_date){
                if (m/(\d{2}\/\d{2}\/\d{4})\s+(\d{2}\:\d{2}\:\d{2})\s+W_NO\s+value=(.*)$/){
                        $end_date = $1;
                        $end_time = $2;
                        my $value = $3;
                        print "$start_date\t$start_time \n$end_date\t$end_time \n";
                        my ($sdate,$smon,$syear) = split("\/",$start_date);
                        my ($edate,$emon,$eyear) = split("\/",$end_date);

                        my ($diff_year,$diff_mon,$diff_days, $diff_hours,$diff_min,$diff_sec) = Delta_YMDHMS($syear,$smon,$sdate,split(":",$start_time),$eyear,$emon,$edate,split(":",$end_time));
                        print "$value \t $diff_year,$diff_mon,$diff_days, $diff_hours,$diff_min,$diff_sec\n";
                        $start_date = '';
                }
        }
        else  {
                if (m/^(\d{2}\/\d{2}\/\d{4})\s+(\d{2}\:\d{2}\:\d{2})\s+TV$/){
                        $start_date = $1;
                        $start_time = $2;
                }
        }
}

I am not sure what you have tried. When in cases where in you donot know how to proceed , it is better to write down the logic in simple steps (ie write the algorithm) and implement it. That will most of the times simplify the whole problem

HTH,
PL

I'm not sure what you want. Is yjhos close?

#!/usr/bin/perl
$tv=0;
$wo=0;
@start=();
@stop=();
while (<>) {
  chomp;
  @stuff=split /\s/;
  if (/TV/ ) {
    $start[$tv++]="$stuff[0] $stuff[1]";
  }
  if (/W_NO/) {
    $stop[$wo++]="$stuff[0] $stuff[1]";
  }
}
$x=0;
foreach (@start) {
  print "$_ $stop[$x++]\n";
}
$ awk '/TV/,/W_NO/' urfile |awk -F[\"] '/value/ {print $2}'
A00005FF.rf
A00008FF.rf
A070058FF.rf
A077758FF.rf

Thank you all for the reply...
Daptal your program does exatctly what I want..exept i get error Date::Calc::Delta_YMDHMS(): not a valid date when I use a day gerater then 11. for example 11/15/2009 07:53:38 will not calculate the difference...

Below the actual log file data, i am still trying to modify the reg expression to capture the phrasees within a long lines of various characters and numbers.

The algorithm for the script for log file from a machine:

  1. Find when the first time TV error occures end of the line with unique phrase ="MMeas"'
  2. The TV error will stop the machine and multiple error might occure afterwards, the script should skip these errors.
  3. Find when the machine start back up (W_NO) and within the long line there is this unique phrase name="WWWW_NO" and the value="A333BBBB.rf"
  4. the output of the script should show (calculate) when the first TV error happens and when the machine start back up. These events could happen through out the day.
  5. Calculate the total time differences of all the events (of waiting between the first error and next machine start).

Best Regards,,,
bataf

Find out if the log file has the date format in dd/mm/yyyy or mm/dd/yyyy , depending on that you have to change the parameters you send to Date::Calc:: Delta_YMDHMS.

My script goes with the assumption that its in the format dd/mm/yy

HTH,
PL

Thanks daptal, I got it and you helped me alot...