3
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.

3

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.

2
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"
}'

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .