I have browsed through the similar threads and they helped me come closest to what I want to do but didn't fully answer my question.
I have a date in the format dd/mm/yyyy hh:mm:ss
($mydate = 26/12/2013 09:42:42
) that I want to convert in unix timestamp via the command:
date -d $mydate +%s
But here the accepted format is this one: yyyy-mm-dd hh:mm:ss
So I did this transformation:
echo $mydate| awk -F' ' '{printf $1}'| awk -F/ '{printf "%s-%s-%s\n",$3,$2,$1}'
And have this ouput:
2013-12-26
Which is good, now I try to append to hour part before doing the conversion:
echo $mydate| awk -F' ' '{printf $1; $hour=$2}'| awk -F/ '{printf "%s-%s-%s %s\n",$3,$2,$1,$hour}'
But then I have this:
2013-12-26 26/12/2013
It seem to not keep the variable $hour
.
I am new in awk, how could I do this ?