Naser Ali wrote: > > Hello Every one, Hello,
> I have attached the samples of the text files from which I am trying to > search and compare certain pattern along with the code. I f you look at the > text file, you will see that from the first sample, there is time value on > line number 2,3,8, and 10 which is highlighted in blue and red and > underlined. Line number two I always want to ignore. Line number 10 has > always the same time as line number 8. I would like to compare the time from > line 8 and 10 to make sure that they are the same and store it in a specail > variable as it is, where as the time from line 3 is different and I would > like to store it in a seperate variable as it is. The problem is that the > time from line line no. 3 can appear on line no. 10 as in sample 2. I also > have attached the code I have written, but it is producing some erroneous > results. Can any one please help. Any pointers will be greatly appreciated. > Regards > > ==================File that contains pattern ---Sample 1 > ===================================== > 1.Executing ef_cron_job_pkg.execall ... > 2. Ended at Tue Feb 26 01:25:09 CST 2002 > 3. Ended at Tue Feb 26 02:17:25 CST 2002 > 4. PL/SQL procedure successfully completed. > 5. Elapsed: 01:30:49.28 > 6. END_TIME > 7. ------------------- > 8. 02/26/2002 02:50:15 > 9. Elapsed: 00:00:00.01 > 10. Ended at Tue Feb 26 02:50:15 CST 2002 > 11. /EFDS/LOADSMENU/operator/cron/run_loads.sh ended at Tue Feb 26 02:50:15 > CST 2002 > ==================File that contains pattern ---Sample 2 > ===================================== > 1. Executing ef_cron_job_pkg.execall ... > 2. Ended at Wed May 22 01:58:19 CDT 2002 > 3. PL/SQL procedure successfully completed. > 4. Elapsed: 01:54:04.67 > 5. END_TIME > 6. ------------------- > 7. 05/22/2002 03:48:49 > 8. Elapsed: 00:00:00.01 > 9. Ended at Wed May 22 03:48:49 CDT 2002 > 10. Ended at Wed May 22 03:59:50 CDT 2002 > 11. /EFDS/LOADSMENU/operator/cron/run_loads.sh ended at Wed May 22 03:59:50 > CDT 2002 > ============================================================================ > = > #!/usr/bin/perl #!/usr/bin/perl -w use strict; > system "cp /dev/null Cron_Dup_Stats_pl.log"; > > open (logfile, ">Cron_Dup_Stats_pl.log"); The open for write will create the file if it doesn't exist and truncate it if it does so the "cp /dev/null" is redundant. You should _always_ check that open was successful. Also, file handles are usually written in upper case. my $log_file = 'Cron_Dup_Stats_pl.log'; open LOGFILE, "> $log_file" or die "Cannot open $logfile: $!"; > print logfile "File Name \tCRON TIME\tDUP ADDR TIME\n"; > print logfile "---------------------\t---------\t-------------\n"; > close(logfile); > > opendir(DIRHANDLE, "/export/home/aknase00/Loads_Scripts/RUN_LOADS_LOGS") or > die "Couldnot open $!"; > #opendir(DIRHANDLE, "/export/home/aknase00/Loads_Scripts") or die "Couldnot > open $!"; > while (defined ($filename = readdir(DIRHANDLE)) ) { > if ($filename =~ /run_loads.*.out/) { Your regular expression looks wrong. Perhaps you want /^run_loads.*\.out$/? > open (gbfile, "$filename"); You should _always_ check that open was successful. Also, file handles are usually written in upper case. open GBFILE, $filename or die "Cannot open $filename: $!"; > @gbfile=<gbfile>; > close (gbfile); > > $i=1; > $j=1; You are using $i as an array index but array indexes start at 0 not 1. > foreach (@gbfile) { > > if ($_ =~ /^Ended at/) { > > #Ended at Thu Feb 28 02:46:43 CST 2002 > > ($a,$b,$day,$day,$mday,$time,$zone,$year)=split(/\s+/,$_); > > chomp($time); chomp is usually used to remove the newline at the end of the line. It is doing nothing useful here. > print "$time\n"; > > ($Ahour,$Amin,$Asec)=split(/:/,$time); > print "$Ahour,$Amin,$Asec\n"; > > $array[$i]=$time; > $array2[$i]=$Ahour.$Amin; > chomp($array[$i]); > chomp($array2[$i]); chomp doing nothing useful here as well. > $i++; > } > } > > foreach (@gbfile) { > > if (/^END_TIME/ .. /[0-9][0-9]\/[0-9][0-9]\/[0-9][0-9][0-9][0-9] > [0-9][0-9]:[0-9][0-9]:[0-9][0-9]/) { > > if ($_ =~ /^[0-9][0-9]\/[0-9][0-9]\/[0-9][0-9][0-9][0-9] > [0-9][0-9]:[0-9][0-9]:[0-9][0-9]/) { > ($CDATE,$CTIME)=split(/ /,$_); > chomp($CTIME); > ($Chour,$Cmin,$Csec)=split(/:/,$CTIME); > } > } > } > if ($array2[2] == $CTIME) { > $DUP=$array[3]; > } > else { > $DUP=$array[2]; > } > chomp($DUP); > > open (logfile, ">>Cron_Dup_Stats_pl.log"); > #print logfile "---------------------\t---------\t-------------\n"; > print logfile "$filename\t$CTIME \t$DUP\n"; > ############################################################################ > } > } > close(logfile); > close(DIRHANDLE); > =========================================================================== Here is some code that is _untested_ but hopefully should give you some ideas: #!/usr/bin/perl -w use strict; my $log_file = 'Cron_Dup_Stats_pl.log'; my $dir = '/export/home/aknase00/Loads_Scripts/RUN_LOADS_LOGS'; open LOGFILE, "> $log_file" or die "Cannot open $logfile: $!"; print LOGFILE "File Name \tCRON TIME\tDUP ADDR TIME\n"; print LOGFILE "---------------------\t---------\t-------------\n"; close LOGFILE; opendir DIRHANDLE, $dir or die "Could not open $dir: $!"; while ( defined( $filename = readdir DIRHANDLE ) ) { next unless $filename =~ /^run_loads.*\.out$/; my ( $time1, $time2, $time3 ); open GBFILE, "$dir/$filename" or die "Cannot open $dir/$filename: $!"; while ( <GBFILE> ) { # $. is the current line number. see: perldoc perlvar if ( $. == 3 and /^Ended at / ) { $time1 = (split)[5]; } if ( $. == 8 and m|^\d+/\d+/\d+/ | ) { $time2 = (split)[1]; } if ( $. == 10 and /^Ended at / ) { $time3 = (split)[5]; } } close GBFILE; if ( $time1 eq $time2 ) { # if the time on line 3 is the same as the time # on line 8 then ?? } } __END__ John -- use Perl; program fulfillment -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]