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

hi I have this input in a file .

<html> ID,21,11814,1,11989,150,Y,10/25/2012 11:36:25 PM,TEST </html>

I need to chaneg the time stamp and make the line read this . how can I convert this to this

<html> ID,21,11814,1,11989,150,Y,10/25/2012 11:36:25 PM, TEST </html>

Thankyou

Replies are listed 'Best First'.
Re: AM to 24 hours
by Loops (Curate) on Aug 05, 2013 at 18:54 UTC
    Hi. Neither sample has an AM in it, both have the same time, and the only difference is there is a space character in front of the word TEST. It's also unclear if the html tags are relevant since they lack body tags or other associated markup. Please clarify your question a bit.
      Hi Let me clarify again hi I have this input in a file .

      ID,21,11814,1,11989,150,Y,10/25/2012 11:36:25 PM,TEST

      "ID",22,11814,1,11989,150,Y,10-25-2012 11:36:25 PM,TEST

      I need to change the time stamp and make the lines look like this . how can I convert this to this using a perl one liner ?

      ID,21,11814,1,11989,150,Y,2012-10-25-23.36.25.0000, TEST

      ID,22,11814,1,11989,150,Y,2012-10-25-23.36.25.0000, TEST

      Thankyou
        This is my first time on the post so :
        ID,21,11814,1,11989,150,Y,10/25/2012 11:36:25 AM,TEST "ID",22,11814,1,11989,150,Y,10-25-2012 11:36:25 PM,TEST
        I need to change the time stamp and make the lines look like this . how can I convert this to this using a perl one liner ?
        ID,21,11814,1,11989,150,Y,2012-10-25-11.36.25.0000, TEST ID,22,11814,1,11989,150,Y,2012-10-25-23.36.25.0000, TEST
Re: AM to 24 hours
by mtmcc (Hermit) on Aug 05, 2013 at 19:01 UTC
Re: AM to 24 hours
by Laurent_R (Canon) on Aug 05, 2013 at 21:37 UTC

    Since you asked for a Perl one-liner, this is one (with a regular expression adapted from 0day's suggestion):

    perl -pe 's/(\d+)\/(\d+)\/(\d+)\s+(\d+):(\d+):(\d+)\s+([AP]M)/join("-" +,$3,$1,$2,($7 eq "PM"?($4+12):$4)).".". join ".",$5,$6,"0000"/e' file +.txt
    But I frankly would not use such a one-liner for anything else than a guaranteed to be a one-off task.