Thanks, I'll check them out. On Wed, Nov 14, 2018 at 11:17 PM Andy Bach <afb...@gmail.com> wrote:
> > Yes the purpose is to compare the timestamps ans yes these are the only > two formats . > > Then you probably want to look at modules, like Date::Manip, google has > lots of suggestions: > > https://stackoverflow.com/questions/4199504/what-is-the-best-way-to-compare-dates-in-perl > https://www.perlmonks.org/?node_id=1100934 > https://metacpan.org/pod/Class::Date > > The first advantage is they'll do the compare for you, the bigger one is > they can parse those date strings automagically. YOu could look at the > built-in POSIX::strftime (perldoc POSIX > strftime > Convert date and time information to string. Returns the > string. > > Synopsis: > > strftime(fmt, sec, min, hour, mday, mon, year, wday > = -1, yday = -1, isdst = -1) > > The month ("mon"), weekday ("wday"), and yearday ("yday") > begin at zero. I.e. January is 0, not 1; Sunday is 0, not 1; January 1st > is 0, not > 1. The year ("year") is given in years since 1900. I.e., > the year 1995 is 95; the year 2001 is 101. Consult your system’s > "strftime()" > manpage for details about these and the other arguments. > > If you want your code to be portable, your format ("fmt") > argument should use only the conversion specifiers defined by the ANSI C > standard > (C89, to play safe). These are "aAbBcdHIjmMpSUwWxXyYZ%". > But even then, the results of some of the conversion specifiers are > non-portable. > For example, the specifiers "aAbBcpZ" change according to > the locale settings of the user, and both how to set locales (the locale > names) and > what output to expect are non-standard. The specifier "c" > changes according to the timezone settings of the user and the timezone > computation rules of the operating system. The "Z" > specifier is notoriously unportable since the names of timezones are > non-standard. > Sticking to the numeric specifiers is the safest route. > > The given arguments are made consistent as though by > calling "mktime()" before calling your system’s "strftime()" function, > except that the > "isdst" value is not affected. > > The string for Tuesday, December 12, 1995. > > $str = POSIX::strftime( "%A, %B %d, %Y", 0, 0, 0, > 12, 11, 95, 2 ); > print "$str\n"; > > you'll have to use the REs to get the pieces (month, date etc) out > yourself that way. Convert the dates to epoch seconds and compare. You do, > apparently, need to take into account timezones, as your date strings: > Calling upgrade.sql on 05-JUL-18 10.19.42.559000 PM -12 > Calling apply.sql on 17.10.18 12:28:12,447849 +02: > > one is -12 the other +2. With a little manipulation, those strings could > be handled by the date utility > $ date -d '05-JUL-18 10:19:42' > Thu Jul 5 10:19:42 CDT 2018 > > $ date -d '10/17/18 12:28:12' > Wed Oct 17 12:28:12 CDT 2018 > > so, for epoch seconds > $ date -d '10/17/18 12:28:12' "+%s" > 1539797292 > $ date -d '05-JUL-18 10:19:42 ' "+%s" > 1530803982 > > That's ignoring TZ > > On Tue, Nov 13, 2018 at 5:38 PM Asad <asad.hasan2...@gmail.com> wrote: > >> Hi Andy , >> >> thanks for the reply . Yes the purpose is to compare the >> timestamps ans yes these are the only two formats . >> >> Thanks, >> >> On Wed, Nov 14, 2018 at 2:48 AM Andy Bach <afb...@gmail.com> wrote: >> >>> Calling upgrade.sql on 05-JUL-18 10.19.42.559000 PM -12 >>> Calling apply.sql on 17.10.18 12:28:12,447849 +02: >>> >>> > I created on regex >>> : \d\d\.\d\d\.\d\d\s[012][0-9]:[0-5][0-9]>:[0-5][0-9] >>> > this only matches : Calling apply.sql on 17.10.18 12:28:12,447849 +02: >>> >>> Right as your first string has word chars for the month, not digits. So, >>> a straight forward, if only lightly useful one would get both, but as >>> they've got entirely different orders, you're not going to be able to do >>> much with the result. You'd be better off looking at 2 separate ones, esp. >>> if you know one will be prefixed by "upgrade" and the other by "apply" or >>> some similar list of words: >>> if ( $str =~ >>> /upgrade.sql\s+on\s+(\d{2}-\w{3}-\d{2})\s+(012][0-9]:[0-5][0-9]:[0-5][0-9])/ >>> # got $1 eq "date-mon-year" and $2 eq "hr-min-sec" >>> or $str =~ >>> /apply.sql\s+on\s+(\d{2}\.\d{2}\.\d{2})\s+([012][0-9]:[0-5][0-9]:[0-5][0-9])/ >>> # got $1 eq "date.month.year" and $2 eq "hr-min-sec" >>> ) { >>> # date str's matched >>> >>> > I need a common regex which matches both the lines ? >>> You might want to let us know why? What you're going to do w/ the match. >>> Are you validating the strings and, if so, will you reject non-matches? >>> Are you looking to break them up into parts, $date, $mon, $year ... ? >>> Compare them, maybe to find the difference? Are these the only 2 formats >>> you'll be looking at, that is, maybe some might be 17.10.2018, or 17-10-18? >>> >>> >>> >>> On Mon, Nov 12, 2018 at 6:49 AM Asad <asad.hasan2...@gmail.com> wrote: >>> >>>> Hi all , >>>> >>>> I have two stings from logfile how can we have a common >>>> regex so that its parse datetime details for further parsing ; >>>> >>>> Calling upgrade.sql on 05-JUL-18 10.19.42.559000 PM -12 >>>> Calling apply.sql on 17.10.18 12:28:12,447849 +02: >>>> >>>> I created on regex : \d\d\.\d\d\.\d\d\s[012][0-9]:[0-5][0-9]:[0-5][0-9] >>>> this only matches : Calling apply.sql on 17.10.18 12:28:12,447849 +02: >>>> >>>> I need a common regex which matches both the lines ? >>>> >>>> >>>> Thanks, >>>> -- >>>> Asad Hasan >>>> +91 9582111698 >>>> >>> >>> >>> -- >>> >>> a >>> >>> Andy Bach, >>> afb...@gmail.com >>> 608 658-1890 cell >>> 608 261-5738 wk >>> >> >> >> -- >> Asad Hasan >> +91 9582111698 >> > > > -- > > a > > Andy Bach, > afb...@gmail.com > 608 658-1890 cell > 608 261-5738 wk > -- Asad Hasan +91 9582111698