<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: command to change date format in Operating System - Linux</title>
    <link>https://community.hpe.com/t5/operating-system-linux/command-to-change-date-format/m-p/4983191#M99829</link>
    <description>Hi Warren:&lt;BR /&gt;&lt;BR /&gt;# perl -pe 's/(.:.:.:)(\d\d\d\d)(\d\d)(\d\d)(\d\d)(\d\d)(\d\d):(.)/$1$2-$3-$4 $5:$6:$7:$8/' file&lt;BR /&gt;&lt;BR /&gt;...and if you want to replace "in-place" do:&lt;BR /&gt;&lt;BR /&gt;# perl -iold -pe 's/(.:.:.:)(\d\d\d\d)(\d\d)(\d\d)(\d\d)(\d\d)(\d\d):(.)/$1$2-$3-$4 $5:$6:$7:$8/' file&lt;BR /&gt;&lt;BR /&gt;...this will leave "file" updated with a backup in "file.old".&lt;BR /&gt;&lt;BR /&gt;Regards!&lt;BR /&gt;&lt;BR /&gt;...JRF...</description>
    <pubDate>Tue, 06 Jun 2006 08:14:16 GMT</pubDate>
    <dc:creator>James R. Ferguson</dc:creator>
    <dc:date>2006-06-06T08:14:16Z</dc:date>
    <item>
      <title>command to change date format</title>
      <link>https://community.hpe.com/t5/operating-system-linux/command-to-change-date-format/m-p/4983187#M99825</link>
      <description>Hi,&lt;BR /&gt;&lt;BR /&gt;I've a log file and the each line have 5 column and want to change the date format in the  4th column.&lt;BR /&gt;&lt;BR /&gt;ORIG -- A:B:C:YYYYMMDDhhmmss:E&lt;BR /&gt;TO   -- A:B:C:YYYY-MM-DD hh:mm:ss:E&lt;BR /&gt;&lt;BR /&gt;i can write a script to convert it but would like to know any simple way or command, like awk command.&lt;BR /&gt;&lt;BR /&gt;THANKS!!&lt;BR /&gt;Warren</description>
      <pubDate>Tue, 06 Jun 2006 07:22:33 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/command-to-change-date-format/m-p/4983187#M99825</guid>
      <dc:creator>Warren_9</dc:creator>
      <dc:date>2006-06-06T07:22:33Z</dc:date>
    </item>
    <item>
      <title>Re: command to change date format</title>
      <link>https://community.hpe.com/t5/operating-system-linux/command-to-change-date-format/m-p/4983188#M99826</link>
      <description>Warren,&lt;BR /&gt;rather messy:&lt;BR /&gt;&lt;A href="http://forums1.itrc.hp.com/service/forums/bizsupport/questionanswer.do?threadId=641226" target="_blank"&gt;http://forums1.itrc.hp.com/service/forums/bizsupport/questionanswer.do?threadId=641226&lt;/A&gt;&lt;BR /&gt;might be quicker to use cut -c</description>
      <pubDate>Tue, 06 Jun 2006 07:30:48 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/command-to-change-date-format/m-p/4983188#M99826</guid>
      <dc:creator>Peter Godron</dc:creator>
      <dc:date>2006-06-06T07:30:48Z</dc:date>
    </item>
    <item>
      <title>Re: command to change date format</title>
      <link>https://community.hpe.com/t5/operating-system-linux/command-to-change-date-format/m-p/4983189#M99827</link>
      <description>&lt;!--!*#--&gt;Hi,&lt;BR /&gt;&lt;BR /&gt;... like awk solution ...&lt;BR /&gt;I keep lines consisting not of 5 columns and invalid date columns unchanged:&lt;BR /&gt;&lt;BR /&gt;awk 'NF==5 {n=split($4,ndate,":"); if (n!=5)  {print;next}&lt;BR /&gt;year=substr(ndate[4],1,4)&lt;BR /&gt;mon=substr(ndate[4],5,2)&lt;BR /&gt;day=substr(ndate[4],7,2)&lt;BR /&gt;hour=substr(ndate[4],9,2)&lt;BR /&gt;min=substr(ndate[4],11,2)&lt;BR /&gt;sec=substr(ndate[4],13)&lt;BR /&gt;printf("%s %s %s %s:%s:%s:%s-%s-%s %s:%s:%s:%s %s\n", $1,$2,$3,ndate[1],ndate[2],ndate[3],year,mon,day,hour,min,sec,ndate[5], $5); next}&lt;BR /&gt;{print}' logfile &amp;gt;logfile.new&lt;BR /&gt;&lt;BR /&gt;mfG Peter</description>
      <pubDate>Tue, 06 Jun 2006 07:44:15 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/command-to-change-date-format/m-p/4983189#M99827</guid>
      <dc:creator>Peter Nikitka</dc:creator>
      <dc:date>2006-06-06T07:44:15Z</dc:date>
    </item>
    <item>
      <title>Re: command to change date format</title>
      <link>https://community.hpe.com/t5/operating-system-linux/command-to-change-date-format/m-p/4983190#M99828</link>
      <description>hi mfG,&lt;BR /&gt;&lt;BR /&gt;the command does not work ... the output file is same as the input file...!?&lt;BR /&gt;&lt;BR /&gt;i tried to debug but can't fix it.&lt;BR /&gt;&lt;BR /&gt;Thanks,&lt;BR /&gt;WAR.&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Tue, 06 Jun 2006 08:00:46 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/command-to-change-date-format/m-p/4983190#M99828</guid>
      <dc:creator>Warren_9</dc:creator>
      <dc:date>2006-06-06T08:00:46Z</dc:date>
    </item>
    <item>
      <title>Re: command to change date format</title>
      <link>https://community.hpe.com/t5/operating-system-linux/command-to-change-date-format/m-p/4983191#M99829</link>
      <description>Hi Warren:&lt;BR /&gt;&lt;BR /&gt;# perl -pe 's/(.:.:.:)(\d\d\d\d)(\d\d)(\d\d)(\d\d)(\d\d)(\d\d):(.)/$1$2-$3-$4 $5:$6:$7:$8/' file&lt;BR /&gt;&lt;BR /&gt;...and if you want to replace "in-place" do:&lt;BR /&gt;&lt;BR /&gt;# perl -iold -pe 's/(.:.:.:)(\d\d\d\d)(\d\d)(\d\d)(\d\d)(\d\d)(\d\d):(.)/$1$2-$3-$4 $5:$6:$7:$8/' file&lt;BR /&gt;&lt;BR /&gt;...this will leave "file" updated with a backup in "file.old".&lt;BR /&gt;&lt;BR /&gt;Regards!&lt;BR /&gt;&lt;BR /&gt;...JRF...</description>
      <pubDate>Tue, 06 Jun 2006 08:14:16 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/command-to-change-date-format/m-p/4983191#M99829</guid>
      <dc:creator>James R. Ferguson</dc:creator>
      <dc:date>2006-06-06T08:14:16Z</dc:date>
    </item>
    <item>
      <title>Re: command to change date format</title>
      <link>https://community.hpe.com/t5/operating-system-linux/command-to-change-date-format/m-p/4983192#M99830</link>
      <description>SIGH!!&lt;BR /&gt;&lt;BR /&gt;how come both the solution not working on my server....!!&lt;BR /&gt;&lt;BR /&gt;#perl -pe 's/(.:.:.:)(\d\d\d\d)(\d\d)(\d\d)(\d\d)(\d\d)(\d\d):(.)/$5:$6:$7:$8/' haha.log&lt;BR /&gt;A:B:C:200606060606:E &lt;BR /&gt;&lt;BR /&gt;....is it bcoz of 06-06-06....?? bad luck on today!?&lt;BR /&gt;&lt;BR /&gt;anyway thanks a lots for the reply.&lt;BR /&gt;&lt;BR /&gt;WAR.&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Tue, 06 Jun 2006 08:29:02 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/command-to-change-date-format/m-p/4983192#M99830</guid>
      <dc:creator>Warren_9</dc:creator>
      <dc:date>2006-06-06T08:29:02Z</dc:date>
    </item>
    <item>
      <title>Re: command to change date format</title>
      <link>https://community.hpe.com/t5/operating-system-linux/command-to-change-date-format/m-p/4983193#M99831</link>
      <description>Hi Warren:&lt;BR /&gt;&lt;BR /&gt;Please post a snippet of your file.  The solutions proposed assume the format of you posted description.&lt;BR /&gt;&lt;BR /&gt;Regards!&lt;BR /&gt;&lt;BR /&gt;...JRF...</description>
      <pubDate>Tue, 06 Jun 2006 08:31:54 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/command-to-change-date-format/m-p/4983193#M99831</guid>
      <dc:creator>James R. Ferguson</dc:creator>
      <dc:date>2006-06-06T08:31:54Z</dc:date>
    </item>
    <item>
      <title>Re: command to change date format</title>
      <link>https://community.hpe.com/t5/operating-system-linux/command-to-change-date-format/m-p/4983194#M99832</link>
      <description>Hi Warren:&lt;BR /&gt;&lt;BR /&gt;You posted as string like "A:B:C:200606060606:E" which looks like it does *not* include the seconds (ss) part.&lt;BR /&gt;&lt;BR /&gt;For that you would need:&lt;BR /&gt;&lt;BR /&gt;# perl -pe 's/(.:.:.:)(\d\d\d\d)(\d\d)(\d\d)(\d\d)(\d\d):(.)/$1$2-$3-$4 $5:$6:$7/' file&lt;BR /&gt;&lt;BR /&gt;...for instance:&lt;BR /&gt;&lt;BR /&gt;# echo " echo "A:B:C:200606060606:E"|perl -pe 's/(.:.:.:)(\d\d\d\d)(\d\d)(\d\d)(\d\d)(\d\d):(.)/$1$2-$3-$4 $5:$6:$7/'&lt;BR /&gt;&lt;BR /&gt;Regards!&lt;BR /&gt;&lt;BR /&gt;...JRF...</description>
      <pubDate>Tue, 06 Jun 2006 08:43:27 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/command-to-change-date-format/m-p/4983194#M99832</guid>
      <dc:creator>James R. Ferguson</dc:creator>
      <dc:date>2006-06-06T08:43:27Z</dc:date>
    </item>
    <item>
      <title>Re: command to change date format</title>
      <link>https://community.hpe.com/t5/operating-system-linux/command-to-change-date-format/m-p/4983195#M99833</link>
      <description>ya.... it is my fault...&lt;BR /&gt;&lt;BR /&gt;JRF, your answner is work and date field does not have "sec".&lt;BR /&gt;&lt;BR /&gt;mfG, i modified the awk and working also.&lt;BR /&gt;&lt;BR /&gt;sed 's/:/ /g' FILE |&lt;BR /&gt;awk '{split($4,ndate);&lt;BR /&gt;year=substr(ndate[1],1,4)&lt;BR /&gt;mon=substr(ndate[1],5,2)&lt;BR /&gt;day=substr(ndate[1],7,2)&lt;BR /&gt;hour=substr(ndate[1],9,2)&lt;BR /&gt;min=substr(ndate[1],11,2)&lt;BR /&gt;printf("%s:%s:%s:%s-%s-%s %s:%s:%s\n",$1,$2,$3,year,mon,day,hour,min,$5); next}&lt;BR /&gt;{print}'&lt;BR /&gt;&lt;BR /&gt;thx again for the reply.&lt;BR /&gt;&lt;BR /&gt;WAR.&lt;BR /&gt;</description>
      <pubDate>Tue, 06 Jun 2006 08:55:45 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/command-to-change-date-format/m-p/4983195#M99833</guid>
      <dc:creator>Warren_9</dc:creator>
      <dc:date>2006-06-06T08:55:45Z</dc:date>
    </item>
    <item>
      <title>Re: command to change date format</title>
      <link>https://community.hpe.com/t5/operating-system-linux/command-to-change-date-format/m-p/4983196#M99834</link>
      <description>lt09:/tmp 113 &amp;gt; cat test.dta&lt;BR /&gt;A:B:C:20060606060606:E&lt;BR /&gt;A:B:C:20060504030201:E&lt;BR /&gt;A:B:C:20050403020102:E&lt;BR /&gt;lt09:/tmp 114 &amp;gt; perl -paF: -e'$F[3]=sprintf"%2d%02d-%02d-%02d %02d:%02d:%02d",unpack"(A2)*",$F[3]and$_=join":",@F' test.dta&lt;BR /&gt;A:B:C:2006-06-06 06:06:06:E&lt;BR /&gt;A:B:C:2006-05-04 03:02:01:E&lt;BR /&gt;A:B:C:2005-04-03 02:01:02:E&lt;BR /&gt;lt09:/tmp 115 &amp;gt;&lt;BR /&gt;&lt;BR /&gt;But I think it is a stupid^wnot so wise idea, as it introduces two new ':' characters that are already used as field separators, making parsing the file harder.&lt;BR /&gt;&lt;BR /&gt;Enjoy, Have FUN! H.Merijn</description>
      <pubDate>Tue, 06 Jun 2006 09:03:02 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/command-to-change-date-format/m-p/4983196#M99834</guid>
      <dc:creator>H.Merijn Brand (procura</dc:creator>
      <dc:date>2006-06-06T09:03:02Z</dc:date>
    </item>
    <item>
      <title>Re: command to change date format</title>
      <link>https://community.hpe.com/t5/operating-system-linux/command-to-change-date-format/m-p/4983197#M99835</link>
      <description>Even shorter:&lt;BR /&gt;&lt;BR /&gt;lt09:/tmp 115 &amp;gt; perl -paF: -e'$F[3]=sprintf"%s%s-%s-%s %s:%s:%s",unpack"(A2)*",$F[3]and$_=join":",@F' test.dta&lt;BR /&gt;A:B:C:2006-06-06 06:06:06:E&lt;BR /&gt;A:B:C:2006-05-04 03:02:01:E&lt;BR /&gt;A:B:C:2005-04-03 02:01:02:E&lt;BR /&gt;lt09:/tmp 116 &amp;gt;&lt;BR /&gt;&lt;BR /&gt;Enjoy, Have FUN! H.Merijn</description>
      <pubDate>Tue, 06 Jun 2006 09:04:30 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/command-to-change-date-format/m-p/4983197#M99835</guid>
      <dc:creator>H.Merijn Brand (procura</dc:creator>
      <dc:date>2006-06-06T09:04:30Z</dc:date>
    </item>
    <item>
      <title>Re: command to change date format</title>
      <link>https://community.hpe.com/t5/operating-system-linux/command-to-change-date-format/m-p/4983198#M99836</link>
      <description>GOOD LUCK!!</description>
      <pubDate>Tue, 06 Jun 2006 09:13:31 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/command-to-change-date-format/m-p/4983198#M99836</guid>
      <dc:creator>Warren_9</dc:creator>
      <dc:date>2006-06-06T09:13:31Z</dc:date>
    </item>
  </channel>
</rss>

