raghvens has asked for the wisdom of the Perl Monks concerning the following question:

Hi PerlGurus, Cheers,

I need your help. I am planning to write a perl script to: I have a big log file where in which there are many lines like:

Starting osci build in ostore_7.4_int_bld.sol2c5.picopt at 2011-09-08- +1702. SUCCESS: Completed osci build in ostore_7.4_int_bld.sol2c5.picopt at 2 +011-09-08-1707. Starting the OSCI build Starting osji build in ostore_7.4_int_bld.sol2c5.picopt at 2011-09-08- +1707. SUCCESS: Completed osji build in ostore_7.4_int_bld.sol2c5.picopt at 2 +011-09-08-1715. Starting xpath build in ostore_7.4_int_bld.sol2c5.picopt at 2011-09-08 +-1715. SUCCESS: Completed xpath build in ostore_7.4_int_bld.sol2c5.picopt at +2011-09-08-1716. Starting ddml build in ostore_7.4_int_bld.sol2c5.picopt at 2011-09-08- +1715. SUCCESS: Completed ddml build in ostore_7.4_int_bld.sol2c5.picopt at 2 +011-09-08-1716. Starting jmtl build in ostore_7.4_int_bld.sol2c5.picopt at 2011-09-08- +1715. SUCCESS: Completed jmtl build in ostore_7.4_int_bld.sol2c5.picopt at 2 +011-09-08-1719. Starting xpath package in ostore_7.4_int_bld.sol2c5.picopt at 2011-09- +08-1719.

I need a script which matches the module names such as osci build, ddml build, osji build, xpath build, etc which has time stamp at the end and store the module name and time in an array and then search for those lines beginning with SUCCESS along the corresponding module names and the time-stamp. Finally give the time difference between the start and complete of the modules. Kindly help.

Replies are listed 'Best First'.
Re: search and give the time difference
by marto (Cardinal) on Sep 09, 2011 at 13:17 UTC

    What have you tried? Please post your efforts along with a list of problems experienced. This isn't a code writing service. Your question is basicly a spec and some example data. The following resources are helpful should you wish to learn Perl:

Re: search and give the time difference
by muba (Priest) on Sep 09, 2011 at 13:31 UTC

    I agree with marto, though here's a few hints to get you started.

    use strict; use warnings; my @starting = (); my @success = (); my @linetypes = ("Starting", "SUCCESS: Completed"); my $linetypes_re = join("|", @linetypes); my @lines = getAllLinesFromTheBigLogFile__ILeaveItAsAnExerciseToYouToD +oThat(); for my $line (@lines) { chomp $line; # makes life so much easier. next unless $line; my ($linetype, $module, $year, $month, $day, $hh, $mm) = $line =~ +m/^($linetypes_re) (.+$) at (\d{4})-(\d{2})-(\d{2})-(\d{2})(\d{2})\.$ +/ my $info = [$module, $year, $month, $day, $hh, $mm]; if ($linetype eq $linetypes[0]) { push @starting, $info; } elsif ($linetype eq $linetypes[1]) { push @succes, $info; } }

    Beware: code is incomplete and untested and might be full of typos, bugs, logical flaws and other oddities. It's just supposed to get you on the right track.

      Many Thanks for immediate replies. Sorry I forgot to mention that there are lines in the log file beginning with Starting which need to considered but there are also lines beginning with Starting stop module name - which are not to be considered, Please suggest how to get rid of these lines in the array @linetypes mentioned in the solution provided? I am trying like this, Kindly suggest:

      use strict; use warnings; my @starting=(); my @success=(); my @linetypes = ("Starting", "SUCCESS: Completed"); my $linetypes_re = join("|", @linetypes); open (LG, "path of the os.log"); @log=<LG>; for my $line (@log) { chomp $line; next unless $line; my ($linetype, $moudle, $year, $month, $day, $hh, $mm) = $line =~ +m/^($linetypes_re) (.+$) at (\d{4})-(\d{2})-(\d{2})-(\d{2})(\d{2})\.$ +/ my $info = [$module, $year, $month, $day, $hh, $mm]; if ($linetype eq $linetypes[0]) { push @starting, $info; } elsif ($linetype eq $linetypes[1]) { push @succes, $info; } }