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,
On Thu, Oct 25, 2018 at 6:44 AM Martin McCormick <[email protected]>
wrote:
> Someone brought to my attention that I had failed to define a
> couple of variables in the sample code I posted and they were
> quite right. I don't mind sharing my work but the entire
> application I wrote to get a brief local weather summary is
> 242 lines and I was trying to stay close to the topic, here, so I
> had shortened it and shortened it a bit too much. Here is sample
> code that will actually run. If you want to experiment with it,
> it should work fron anywhere in the world but practically, I
> doubt it works outside the united states though people in other
> countries can look up weather in US cities if you first get on the
> noaa.gov web site
>
> http://noaa.gov
>
> and enter the city name you are interested in. If you have a US
> postal zip code, that will work. What you want is an xml file
> containing the local weather conditions for that location. You
> will also get latitude and longitude which can help you get
> sunrise and sunset data from another web site that needs those
> data to give you the right table.
>
> In other words, you must set $wxfile to the name of the file for
> your city of interest.
>
> This code downloads the file for Stillwater, Oklahoma and
> the information in the xml file says that the recommend pickup
> time is 15 minutes past the hour so it modifies the time stamp to
> show 15 minutes past your current hour. When you look at the
> code, you will see that it compares the current number of
> localtime seconds to the mtime value of the present file. It
> will not get it again until 3600 seconds or 1 hour has passed
> since 15 minutes past the hour in which you downloaded it.
>
> Here is working code. I did run it through perltidy but no
> telling what the mailing process will do so you will need to
> probably run perltidy again after you save the code.
>
> I am sorry for any confusion I caused.
>
> Cut here.
>
> #!/usr/bin/perl -w
> use strict;
> use warnings::unused;
> use Data::Dumper;
> use XML::Simple;
> use File::Basename;
> use Cwd;
> use File::stat;
> use Time::Local;
> my $homedir = "/tmp";
> my @t = localtime(time);
> my $utcsec = timelocal(@t);
> my $wxfile = 'display.php?stid=KSWO';
>
> #I want that file to end up in a specific directory so:
> my $wxpath = $homedir . "/" . $wxfile;
> my $day = 86400; #seconds
> my $hour = 3600;
> my $gmt_offset_in_seconds = timegm(@t) - timelocal(@t);
> my $tzoffset = $gmt_offset_in_seconds / 3600;
>
> #many thanks to whoever wrote the quick way to determine TZ
> #offset from utc
>
> my $wxlast_update_time;
>
> #Grab conditions from NOAA if the file is stale or missing.
> if ( !stat($wxpath) ) { #The file is not there.
> system(
> "curl -s -o $wxpath 'http://w1.weather.gov/xml/current_obs/$wxfile
> '");
>
> #Change the mtime to a quarter past last hour.
> my $when = timelocal( 0, 15, $t[2], $t[3], $t[4], ( $t[5] - 100 ) );
> utime $when, $when, "$wxpath";
> } #The file is not there.
> else { #what normally happens
> my $wxstatRef = stat($wxpath);
> $wxlast_update_time = $wxstatRef->mtime();
> my $wxage = ( $utcsec - $wxlast_update_time );
> if ( $wxage >= $hour ) { #File needs to be refreshed.
>
> #The file should not be more than 3600 seconds old.
> system(
> "curl -s -o $wxpath '
> http://w1.weather.gov/xml/current_obs/$wxfile'"
> );
>
> #Change the mtime to a quarter past.
> my $when = timelocal( 0, 15, $t[2], $t[3], $t[4], ( $t[5] - 100 )
> );
> utime $when, $when, "$wxpath";
> } #File needs to be refreshed.
> } #what normally happens
>
> # create object
> my $xml = new XML::Simple;
>
> # read XML file
> my $data = $xml->XMLin("$wxpath");
>
> print Dumper($data);
>
> --
> To unsubscribe, e-mail: [email protected]
> For additional commands, e-mail: [email protected]
> http://learn.perl.org/
>
>
>
--
Asad Hasan
+91 9582111698