2

I have a program which logs like this:

1324218770.7644 INFO etc

What's the best Linux shell program to pipe that through to change the timestamps to a human readable format like Sun 18 Dec 2011 15:32:50 CET?

I can pipe like this through

| cut -f 1 -d\   | awk '{print strftime("%c",$1)}'

for the timestamps only, but how do I maintain the rest of the line?

2 Answers 2

3

just override $1, then print all line

$ echo '1324218770.7644 INFO etc' | awk '{$1=strftime("%c", $1); print}'
2

I assume that you want the date to be changed inline, printing the rest of the line as well. Try replacing field 1 with the output of strftime().

$ echo "1234218770.7644 INFO etc' | awk '{$1=strftime("%c", $1); print}'
Mon 09 Feb 2009 05:32:50 PM EST INFO etc
3
  • %s gives me the timestamp - Maybe's its an awk version thing.
    – Keith
    Commented Dec 18, 2011 at 18:44
  • Nope. Meant to type %c when I copied from the terminal. Thanks for the catch.
    – Arcege
    Commented Dec 18, 2011 at 19:28
  • How did you get the output? Your quotes are kinda messed up in the echo statement. Commented Dec 19, 2011 at 18:13

You must log in to answer this question.

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