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?

link|improve this question
feedback

2 Answers

just override $1, then print all line

$ echo '1324218770.7644 INFO etc' | awk '{$1=strftime("%c", $1); print}'
link|improve this answer
feedback

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
link|improve this answer
%s gives me the timestamp - Maybe's its an awk version thing. – Keith Dec 18 '11 at 18:44
Nope. Meant to type %c when I copied from the terminal. Thanks for the catch. – Arcege Dec 18 '11 at 19:28
How did you get the output? Your quotes are kinda messed up in the echo statement. – Jaypal Singh Dec 19 '11 at 18:13
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.