Skip to content
Advertisement

Date manipulation in awk variable : Non Military Format

In the mentioned code : | awk '{ print $1, $2 }' AWK $2 is having “Thu Nov 19 17:00:00 2015” in it. I want to manipulate this date String there only in inline awk in Non Military format “Thu Nov 19 05:00:00 PM 2015“. Please help.

Advertisement

Answer

This line should give you the expected format:

kent$  echo "Thu Nov 19 17:00:00 2015"|awk '{d=$0;cmd="date -d""d"" +"%a %b %d %r %Y"" ;cmd|getline $0;close(cmd)}7'
Thu Nov 19 05:00:00 PM 2015

Here you go:

kent$  echo "FOO,Thu Nov 19 17:00:00 2015"|awk -F, '{d=$2;cmd="date -d""d"" +"%a %b %d %r %Y"" ;cmd|getline $2;close(cmd);print "col1:"$1 RS "col2:"$2}'        
col1:FOO
col2:Thu Nov 19 05:00:00 PM 2015
User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement