<?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: How to change date format using sed or awk in Operating System - HP-UX</title>
    <link>https://community.hpe.com/t5/operating-system-hp-ux/how-to-change-date-format-using-sed-or-awk/m-p/3335990#M189849</link>
    <description>sed would be something like this:&lt;BR /&gt;&lt;BR /&gt;sed 's!|\(..\)/\(..\)/\(..\)|!|\3/\1/\2|!' yourFile</description>
    <pubDate>Tue, 20 Jul 2004 09:29:49 GMT</pubDate>
    <dc:creator>curt larson_1</dc:creator>
    <dc:date>2004-07-20T09:29:49Z</dc:date>
    <item>
      <title>How to change date format using sed or awk</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/how-to-change-date-format-using-sed-or-awk/m-p/3335981#M189840</link>
      <description>Hi,&lt;BR /&gt;&lt;BR /&gt;I've got a text file in the following format:&lt;BR /&gt;&lt;BR /&gt;abcdefg|MM/DD/YY|00:30|xyzxyz&lt;BR /&gt;where MM=month, DD=day and YY=year&lt;BR /&gt;&lt;BR /&gt;How can I change the format into:&lt;BR /&gt;&lt;BR /&gt;abcdefg|YY/MM/DD|00:30|xyzxyz&lt;BR /&gt;&lt;BR /&gt;using sed or awk?&lt;BR /&gt;&lt;BR /&gt;Thanks in advance&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Tue, 20 Jul 2004 03:29:06 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/how-to-change-date-format-using-sed-or-awk/m-p/3335981#M189840</guid>
      <dc:creator>Eric Leung_2</dc:creator>
      <dc:date>2004-07-20T03:29:06Z</dc:date>
    </item>
    <item>
      <title>Re: How to change date format using sed or awk</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/how-to-change-date-format-using-sed-or-awk/m-p/3335982#M189841</link>
      <description>Hi,&lt;BR /&gt;&lt;BR /&gt;Try this script procedure:&lt;BR /&gt;&lt;BR /&gt;TEXT=`cat text_file`&lt;BR /&gt;FIELD_1=`echo $TEXT|awk -F"|" '{ print $1 }'`&lt;BR /&gt;FIELD_2=`echo $TEXT|awk -F"|" '{ print $2 }'`&lt;BR /&gt;FIELD_3=`echo $TEXT|awk -F"|" '{ print $3 }'`&lt;BR /&gt;FIELD_4=`echo $TEXT|awk -F"|" '{ print $4 }'`&lt;BR /&gt;DATE=`echo $FIELD_2|awk -F"/" '{ print $3"/"$1"/"$2 }'`&lt;BR /&gt;echo "$FIELD_1|$DATE|$FIELD_3|$FIELD_4" &amp;gt; text_file&lt;BR /&gt;&lt;BR /&gt;Rgds.</description>
      <pubDate>Tue, 20 Jul 2004 03:49:29 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/how-to-change-date-format-using-sed-or-awk/m-p/3335982#M189841</guid>
      <dc:creator>Jose Mosquera</dc:creator>
      <dc:date>2004-07-20T03:49:29Z</dc:date>
    </item>
    <item>
      <title>Re: How to change date format using sed or awk</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/how-to-change-date-format-using-sed-or-awk/m-p/3335983#M189842</link>
      <description>Here ia another way. file is parameter&lt;BR /&gt;&lt;BR /&gt;filein=$1&lt;BR /&gt;  cat $filein|while read linein&lt;BR /&gt;  do&lt;BR /&gt;    OLDIFS=$IFS&lt;BR /&gt;    export IFS="|"&lt;BR /&gt;    echo "$linein"|read a b c d&lt;BR /&gt;    export IFS="/"&lt;BR /&gt;    echo "$b"|read e f g&lt;BR /&gt;    export IFS=$OLDIFS&lt;BR /&gt;    echo "$a""|""$g""/""$e""/""$f""|""$c""|""$d"&lt;BR /&gt;  done&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;              Steve Steel</description>
      <pubDate>Tue, 20 Jul 2004 04:08:42 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/how-to-change-date-format-using-sed-or-awk/m-p/3335983#M189842</guid>
      <dc:creator>Steve Steel</dc:creator>
      <dc:date>2004-07-20T04:08:42Z</dc:date>
    </item>
    <item>
      <title>Re: How to change date format using sed or awk</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/how-to-change-date-format-using-sed-or-awk/m-p/3335984#M189843</link>
      <description>Thanks for your replies and maybe I need to define my problem more clearly.&lt;BR /&gt;&lt;BR /&gt;Actually, I need to change five different files and the number of fields varies from file to file. Unfortunately, there are more than 20 fields in some files.&lt;BR /&gt;&lt;BR /&gt;Hence, it would be better if there is a function to handle all these files.&lt;BR /&gt;&lt;BR /&gt;Thanks.</description>
      <pubDate>Tue, 20 Jul 2004 04:19:00 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/how-to-change-date-format-using-sed-or-awk/m-p/3335984#M189843</guid>
      <dc:creator>Eric Leung_2</dc:creator>
      <dc:date>2004-07-20T04:19:00Z</dc:date>
    </item>
    <item>
      <title>Re: How to change date format using sed or awk</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/how-to-change-date-format-using-sed-or-awk/m-p/3335985#M189844</link>
      <description>It is good to operate it with the awk. There are | and / can be used as field separators.&lt;BR /&gt;&lt;BR /&gt; FLD="abcdefg|MM/DD/YY|00:30|xyzxyz"&lt;BR /&gt; echo "$(echo $FLD | awk -F "|" '{ print $1 }')|$(echo $FLD | awk -F "|" '{ print $2 }' | awk -F "/" '{ print $3"/"$2"/"$1 }')|$(echo $FLD | awk -F "|" '{ print $3"|"$4 }')"&lt;BR /&gt;&lt;BR /&gt; It will give you the desired output.</description>
      <pubDate>Tue, 20 Jul 2004 04:20:47 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/how-to-change-date-format-using-sed-or-awk/m-p/3335985#M189844</guid>
      <dc:creator>Muthukumar_5</dc:creator>
      <dc:date>2004-07-20T04:20:47Z</dc:date>
    </item>
    <item>
      <title>Re: How to change date format using sed or awk</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/how-to-change-date-format-using-sed-or-awk/m-p/3335986#M189845</link>
      <description>or&lt;BR /&gt; &lt;BR /&gt;perl -pne 's#(..)/(..)/(..)#$3/$1/$2#' textfile &amp;gt; newfile</description>
      <pubDate>Tue, 20 Jul 2004 04:21:56 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/how-to-change-date-format-using-sed-or-awk/m-p/3335986#M189845</guid>
      <dc:creator>Mark Grant</dc:creator>
      <dc:date>2004-07-20T04:21:56Z</dc:date>
    </item>
    <item>
      <title>Re: How to change date format using sed or awk</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/how-to-change-date-format-using-sed-or-awk/m-p/3335987#M189846</link>
      <description>Get line by line from a file as,&lt;BR /&gt; &lt;BR /&gt; fun1()&lt;BR /&gt; { &lt;BR /&gt;  filename=$1 &lt;BR /&gt;  newfile=/tmp/test.log&lt;BR /&gt;  rm -f $newfile&lt;BR /&gt;  touch $newfile&lt;BR /&gt;&lt;BR /&gt;  while read line; do&lt;BR /&gt;   echo line | grep -q "[[:alpha:]]*/[[:alpha:]]*/[[:alpha:]]"&lt;BR /&gt;   if [[ $? -eq 0 ]]; then&lt;BR /&gt;     operation of awk to change the format &amp;gt;&amp;gt; newfile&lt;BR /&gt;   else&lt;BR /&gt;     echo $file &amp;gt;&amp;gt;newfile&lt;BR /&gt;   done &amp;lt; filename&lt;BR /&gt;  &lt;BR /&gt;   mv $newfile $filename&lt;BR /&gt; &lt;BR /&gt;  }&lt;BR /&gt; &lt;BR /&gt; fun1 &lt;FILENAME1&gt;&lt;BR /&gt;  ...&lt;BR /&gt; fun1 &lt;FILENAME2&gt;&lt;BR /&gt;&lt;BR /&gt; It is good to have your file examples to make a scipt appropriate to ur requirement.&lt;/FILENAME2&gt;&lt;/FILENAME1&gt;</description>
      <pubDate>Tue, 20 Jul 2004 04:31:41 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/how-to-change-date-format-using-sed-or-awk/m-p/3335987#M189846</guid>
      <dc:creator>Muthukumar_5</dc:creator>
      <dc:date>2004-07-20T04:31:41Z</dc:date>
    </item>
    <item>
      <title>Re: How to change date format using sed or awk</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/how-to-change-date-format-using-sed-or-awk/m-p/3335988#M189847</link>
      <description>Without sed, without awk ? just cut it :)&lt;BR /&gt;&lt;BR /&gt;$&amp;gt;cat file&lt;BR /&gt;abcdefg|MM/DD/YY|00:30|xyzxyz&lt;BR /&gt;jdfds|07/20/04|HH:MM|jsfklm&lt;BR /&gt;fdslmkqjfq|06/15/03|23:14|jfds&lt;BR /&gt;$&amp;gt;for i in `cat file`&lt;BR /&gt;&amp;gt; do&lt;BR /&gt;&amp;gt; echo "`echo $i | cut -d '|' -f 1`|\c"&lt;BR /&gt;&amp;gt; echo "`echo $i | cut -d '|' -f 2 | cut -d '/' -f 2`/\c"&lt;BR /&gt;&amp;gt; echo "`echo $i | cut -d '|' -f 2 | cut -d '/' -f 1`/\c"&lt;BR /&gt;&amp;gt; echo "`echo $i | cut -d '|' -f 2 | cut -d '/' -f 3`|\c"&lt;BR /&gt;&amp;gt; echo "`echo $i | cut -d '|' -f 3,4`"&lt;BR /&gt;&amp;gt; done&lt;BR /&gt;abcdefg|DD/MM/YY|00:30|xyzxyz&lt;BR /&gt;jdfds|20/07/04|HH:MM|jsfklm&lt;BR /&gt;fdslmkqjfq|15/06/03|23:14|jfds&lt;BR /&gt;&lt;BR /&gt;Regards,&lt;BR /&gt;&lt;BR /&gt;Fred&lt;BR /&gt;</description>
      <pubDate>Tue, 20 Jul 2004 05:25:35 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/how-to-change-date-format-using-sed-or-awk/m-p/3335988#M189847</guid>
      <dc:creator>Fred Ruffet</dc:creator>
      <dc:date>2004-07-20T05:25:35Z</dc:date>
    </item>
    <item>
      <title>Re: How to change date format using sed or awk</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/how-to-change-date-format-using-sed-or-awk/m-p/3335989#M189848</link>
      <description>cat yourFile |&lt;BR /&gt;awk -F"|" '{&lt;BR /&gt;split($2,a,"/");&lt;BR /&gt;$2=sprintf("%s/%s/%s",a[3],a[1],a[2]);&lt;BR /&gt;print $0;&lt;BR /&gt;}'&lt;BR /&gt;&lt;BR /&gt;i don't have my computer running to test that, but it should be pretty close to what you need.</description>
      <pubDate>Tue, 20 Jul 2004 09:21:50 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/how-to-change-date-format-using-sed-or-awk/m-p/3335989#M189848</guid>
      <dc:creator>curt larson_1</dc:creator>
      <dc:date>2004-07-20T09:21:50Z</dc:date>
    </item>
    <item>
      <title>Re: How to change date format using sed or awk</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/how-to-change-date-format-using-sed-or-awk/m-p/3335990#M189849</link>
      <description>sed would be something like this:&lt;BR /&gt;&lt;BR /&gt;sed 's!|\(..\)/\(..\)/\(..\)|!|\3/\1/\2|!' yourFile</description>
      <pubDate>Tue, 20 Jul 2004 09:29:49 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/how-to-change-date-format-using-sed-or-awk/m-p/3335990#M189849</guid>
      <dc:creator>curt larson_1</dc:creator>
      <dc:date>2004-07-20T09:29:49Z</dc:date>
    </item>
    <item>
      <title>Re: How to change date format using sed or awk</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/how-to-change-date-format-using-sed-or-awk/m-p/3335991#M189850</link>
      <description>If you want a function within "awk" so you can call it multiple times, here is a sample-&lt;BR /&gt; &lt;BR /&gt;echo "hello|10/17/03|abc" | awk -F\| 'function swap(x) { split(x,a,"/"); return a[3] "/" a[2] "/" a[1] };{print swap($2)}'&lt;BR /&gt; &lt;BR /&gt;You can call "swap" multiple times within your awk script. My sample is a one-line but you may want to put the awk script into a seperate file.&lt;BR /&gt; &lt;BR /&gt;HTH&lt;BR /&gt; &lt;BR /&gt;-- Rod Hills</description>
      <pubDate>Tue, 20 Jul 2004 09:32:10 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/how-to-change-date-format-using-sed-or-awk/m-p/3335991#M189850</guid>
      <dc:creator>Rodney Hills</dc:creator>
      <dc:date>2004-07-20T09:32:10Z</dc:date>
    </item>
  </channel>
</rss>

