i trying convert unix time date , time;
1436876820 blah1 stop none john 1436876820 blah0 continu none john 1436876821 blah2 stop bob i convert first column have 2 more column date , time below
14-07-15 13:27:00 blah1 stop none john 14-07-15 13:27:00 blah0 continu none john 14-07-15 13:27:01 blah2 stop bob etc.. so have started following.
in="${1}" in $(awk '{print $1}' ${in}); dd=$(date -d @${i} +'%d-%m-%y %h:%m:%s') awk '{ ${1}="'"${dd}"'" }' < ${in} done this not work due syntax , give such of error:
awk: { ${1}="14-07-2015 13:27" } awk: ^ syntax error i use sed instead of awk:
sed "s/^1........./${dd}/" ${in} any awk welcome. al.
get rid of shell loop , 1 awk invocation:
awk '{ cmd = "date -d @" $1 " +\"%d-%m-%y %h:%m:%s\"" if ( (cmd | getline dd) > 0 ) { $1 = dd } close(cmd) print }' "$1" if have gnu awk can use it's internal strftime() instead of date+getline:
awk '{ $1 = strftime("%d-%m-%y %h:%m:%s",$1) print }' "$1"
Comments
Post a Comment