Convert an epoch date to human readable format?
echo "$some_string" | awk -F '|' '{print $1 $2}'
$2
is a epoch date and I want to convert it to human readable format. I tried doing date -r $2
but no luck.
If you can get GNU awk on your mac (via homebrew), you can do:
gawk '{print $1, strftime("%Y-%m-%d %H:%M:%S", $2)}'
flavour your datetime formatting to suit.
Otherwise, you can call date from inside awk:
awk '{
cmd = "date -d \"@" $2 "\" \"+%Y-%m-%d %H:%M:%S\""
cmd | getline datetime
close(cmd)
print $1, datetime
}'
I don't have access to a mac, so you'll need to adjust your date arguments accordingly.
echo "$some_text" | awk -F'|' '{
cmd = "date -r "$2" \"+%Y-%m-%d %H:%M:%S\""
cmd | getline datetime
close(cmd)
print "text: "$1 "\ndate: "datetime"\n"
}'