我试图在这里和其他来源找到答案,但我不知所措。我正在构建一个小小的 awk 工具,用于基于控制台的 twitter 客户端 twidge ( https://github.com/jgoerzen/twidge/wiki )
从传入推文的输出中,我想做各种很酷的事情,但为了使数据有用,我需要首先将时间戳转换为我可以处理的格式。
作为参考,这是我当前使用命令获得的输出
代码
twidge lsrecent -l | gawk -F"\t" '{print "@"$2 ": " $4 " ("$5")"}'
输出
@nytimes: China Cuts Ties With North Korean Bank http://t.co/N3iljjgGbH (Tue May 07 12:57:04 +0000 2013)
然后我试图变得聪明并做到了
代码
twidge lsrecent -l | gawk -F"\t" '{print "@"$2 ": " $4 " ("strftime("%Y-%m-%d %T",$5)")"}'
但是得到了这个不幸的输出
@BloombergNews: HSBC posts bigger-than-estimated increase in first-quarter profit | http://t.co/QraWonRU32 (1970-01-01 01:00:00)
正如我们所看到的,日期转换并不像希望的那样。任何指针最受欢迎。它不必是 awk/gawk 它只是一个偏好。最终,数据将被放入数据库并在那里进行处理。
谢谢!
马丁