【发布时间】:2014-12-26 07:09:51
【问题描述】:
我有一个文件,一个字段是像20141028 20:49:49这样的时间戳,我想得到20的小时,所以我使用system命令:
hour=system("date -d\""$5"\" +'%H'")
时间戳是我文件中的第五个字段,所以我使用了$5。但是当我执行程序时,我发现上面的命令只是输出20并返回0所以hour is 0 but not 20,所以我的问题是如何获取时间戳中的小时?
我知道一个使用split函数两次的方法:
split($5, vec, " " )
split(vec[2], vec2, ":")
但是这种方法有点低效和丑陋。
还有其他解决方案吗?谢谢
【问题讨论】:
-
具体来说,this answer.
-
@nu11p01n73R 我的错误,已更正谢谢
-
@TheParamagneticCroissant 我读了你给的帖子。根据我应该使用
last_time_over_budget_in_hour="date -d" " +'%H'" $5 | getline的方法,但这是错误的。区别是the awk variable in the post is just after the shell command但这里的awk变量在shell命令的中间` -
@nu11p01n73R 没有,但我只是想知道这种方式的方法
标签: awk