(Please reply to the list.)

If you have written code that extracts the date and time from the ‘LOG flle 
opened’ lines in the log file, then please show us your code. You seem to be 
asking other people to write your program for you. You will get better help if 
you appear to be making an effort to solve these problems yourself.

Anyone wishing to get help from a forum such as beginners@perl.org would do 
well to read this website on how to ask smart questions:

<http://www.catb.org/~esr/faqs/smart-questions.html>

Now, to address your problem:

If you have a starting time and an ending time for a window within which you 
wish to print lines from a log file, you can use a flag variable to indicate 
when the lines you are reading are within that window. The pseudo-logic would 
be something like this:

1.initialize print flag to false
2. Save starting and ending times in variables
3. loop to read or process sequential lines in the file
  a. See if line contains time
  b. If it does, extract time
  c. Compare time in line to starting time
  d. If line time is greater than or equal to start time, set print flag to true
  e. If line time is greater than ending time, set print flag to false
  f. If print flag is true print line
  g. End of loop — process next line

If you need help with any of these steps, please show us your code, what your 
code is doing, and what you expect your code to do that it is not doing.

Thanks.
 
> On Oct 24, 2018, at 10:50 PM, Asad <asad.hasan2...@gmail.com> wrote:
> 
> Hi Jim/All,
> 
>              I have already done that now the issue is how do I  print  the 
> lines from file2 only between start $t2 and <$t3  then process these lines is 
> next step ?
>              Please share the code if you have .
> 
> Thanks,    
> 
> 
> On Thu, Oct 25, 2018 at 11:04 AM Jim Gibson <jimsgib...@gmail.com> wrote:
> 
> 
> > On Oct 24, 2018, at 9:54 PM, Asad <asad.hasan2...@gmail.com> wrote:
> > 
> > Thank all now I am able to progress :
> > 
> > file1  i am able to extract the start and end timestamp 
> > file 2  i am able to extract the timestamp 
> > 
> > used the following 
> > my $t1 = Time::Piece->strptime('Feb 23 01:10:28 2018', '%b %d %H:%M:%S 
> > %Y'); coming from file1
> > 
> > my $t2 = Time::Piece->strptime('02/23/18 01:10:33', '%m/%d/%y %H:%M:%S');   
> >     coming from file2
> > 
> > my $t3 = Time::Piece->strptime('Feb 23 01:10:36 2018', '%b %d %H:%M:%S 
> > %Y');  coming from file 1
> > 
> > if ($t2 > $t1 and $t2 < $t3) { ... }   till here it working fine
> > 
> >  now I would like to print all lines from file2 starting from  t2 02/23/18 
> > 01:10:33 till very next timestamp which will be  greater than t3 :
> > 
> > 
> > 
> > for example the file2  would look like this:
> > 
> > ===========================================================================================================
> > 
> >  LOG file opened at 02/23/18 01:10:33
> > 
> > ERR-05007:   Warning: Intra source concurrency disabled because the 
> > preprocessor option is being used.
> > 
> > Field Definitions for table OPATCH_XML_INV
> > 
> > eject rows with all null fields
> > 
> >   Fields in Data Source: 
> > 
> > 
> > 
> > ERR-04095:failed: Unable to create patchObject
> > 
> > Possible causes are:
> > 
> >  "
> > 
> >  LOG file opened at 04/26/18 06:10:33
> > 
> > ===========================================================================================================
> >   
> > 
> > This logfile may have other time but i would to extract only the above 
> > lines because messages occured between t1 and t3 after I extract these i 
> > want to print the error lines for example ERR-05007
> > 
> > the issue I am facing if there are multiple error in the file it is 
> > printing for each occurance of  ERR-05007 instead it should print only the 
> > error lines between t1 and t3 from file2
> > 
> > Please advice ,
> > 
> > thanks,
> 
> For each line is the file, use a regular expression to look for lines 
> starting with ‘LOG file opened at’ and extract the time that follows in that 
> line. Then, use Time::Piece to create an object of that class using the 
> date/time extracted. Then, you can compare the time in that line to your 
> start and stop times in $t2 and $t3 (or is it $t1 and $t3?).
> 
> 
> Jim Gibson
> 
> -- 
> To unsubscribe, e-mail: beginners-unsubscr...@perl.org
> For additional commands, e-mail: beginners-h...@perl.org
> http://learn.perl.org/
> 
> 
> 
> 
> -- 
> Asad Hasan
> +91 9582111698

Jim Gibson

--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to