Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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?

share|improve this question
add comment

2 Answers

up vote 2 down vote accepted

just override $1, then print all line

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

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
share|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 Dec 19 '11 at 18:13
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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