如何将装满unix时间字符串的文件转换为人类可读的日期? [英] How can I convert a file full of unix time strings to human readable dates?

查看:54
本文介绍了如何将装满unix时间字符串的文件转换为人类可读的日期?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在处理一个充满unix时间字符串的文件.我想将它们全部转换为人类可读的语言.

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

文件看起来像这样:

1153335401
1153448586
1153476729
1153494310
1153603662
1153640211

这是脚本:

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

这不起作用.我得到的输出是 1970年1月1日星期四00:00:00 .我认为换行符正在被拾取,这就是为什么它不起作用的原因.有任何想法吗?我正在使用Mac OSX,这有什么不同.

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.

推荐答案

$ perl -lne 'print scalar gmtime $_' test.txt
Wed Jul 19 18:56:41 2006
Fri Jul 21 02:23:06 2006
Fri Jul 21 10:12:09 2006
Fri Jul 21 15:05:10 2006
Sat Jul 22 21:27:42 2006
Sun Jul 23 07:36:51 2006

这篇关于如何将装满unix时间字符串的文件转换为人类可读的日期?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆