How can I convert a file full of unix time strings to human readable dates?

Posted by skymook on Stack Overflow See other posts from Stack Overflow or by skymook
Published on 2010-05-17T14:16:17Z Indexed on 2010/05/18 0:00 UTC
Read the original article Hit count: 244

Filed under:
|
|

I am processing a file full of unix time strings. I want to convert them all to human readable.

The file looks like so:

1153335401
1153448586
1153476729
1153494310
1153603662
1153640211

Here is the script:

#! /bin/bash
FILE="test.txt"
cat $FILE | while read line; do
perl -e 'print scalar(gmtime($line)), "\n"'
done

This is not working. The output I get is Thu Jan 1 00:00:00 1970 for every line. I think the line breaks are being picked up and that is why it is not working. Any ideas? I'm using Mac OSX is that makes any difference.

© Stack Overflow or respective owner

Related posts about bash

Related posts about perl