why post a python solution here?
On Thu, Oct 25, 2018 at 8:58 AM Asad <[email protected]> wrote:
> Hi ,
>
> Yes i have the code :
>
> import re
> import datetime
> from datetime import timedelta
>
> Header = "*****************************************************"
>
> f3 = open ( r"D:\QI\logA.txt", 'r' )
> string = f3.read ()
> regex = re.compile ( "\n" )
> st = regex.sub ( " ", string )
> st1 = st.split ( " " )
>
> if re.search ('ERR-1:', st ):
> x = re.findall ( "(\w{3})\s+([0-9]{2})\s+(\d+):(\d+):(\d+)\s+(\d+)", st )
> j = x[0][0] + " "+ x[0][1]+" " + x[0][2] +":"+ x[0][3]+":" + x[0][4]+" "
> + x[0][5]
> h = x[1][0] + " "+ x[1][1]+" "+ x[1][2] +":" + x[1][3] +":"+ x[1][4] +"
> "+ x[1][5]
> y = datetime.datetime.strptime ( j, '%b %d %H:%M:%S %Y' )
> print y
> k = datetime.datetime.strptime ( h, '%b %d %H:%M:%S %Y' )
> print k
>
> f4 = open ( r"D:\QI\logC11.txt", 'r' )
>
> string1 = f4.read ()
> reg = re.compile ( "\n" )
> newst = reg.sub ( " ", string1 )
> newst1 = newst.split ( " " )
>
> if re.search ( "ERR-2", newst ):
> a = re.findall ( "\d\d/\d\d/\d\d\s[012][0-9]:[0-5][0-9]:[0-5][0-9]",
> newst )
> for i in range ( len ( a ) ):
> newtime = datetime.datetime.strptime ( a[i], '%m/%d/%y %H:%M:%S' )
> if newtime > y and newtime < k:
> print "Install patch1"
>
> if re.search ( "ERR-3", newst ):
> a = re.findall ( "\d\d/\d\d/\d\d\s[012][0-9]:[0-5][0-9]:[0-5][0-9]",
> newst )
> for i in range ( len ( a ) ):
> newtime = datetime.datetime.strptime ( a[i], '%m/%d/%y %H:%M:%S' )
> if newtime > y and newtime < k:
> print newtime, y, k
> print "Install patch2"
>
> ==============================================================================================
>
> output i get :
>
> *Install patch1 - wrong solution
> 2018-10-22 10:21:23 2018-10-22 10:21:15 2018-10-22 10:21:25
> Install patch2 - correct solution *
>
>
>
>
>
> On Thu, Oct 25, 2018 at 6:56 PM Jim Gibson <[email protected]> wrote:
>
>> (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 [email protected] 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 <[email protected]> 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 <[email protected]>
>> wrote:
>> >
>> >
>> > > On Oct 24, 2018, at 9:54 PM, Asad <[email protected]> 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: [email protected]
>> > For additional commands, e-mail: [email protected]
>> > http://learn.perl.org/
>> >
>> >
>> >
>> >
>> > --
>> > Asad Hasan
>> > +91 9582111698
>>
>> Jim Gibson
>>
>>
>>
>>
>
> --
> Asad Hasan
> +91 9582111698
> --
> To unsubscribe, e-mail: [email protected]
> For additional commands, e-mail: [email protected]
> http://learn.perl.org/
>