cat test.txt |
awk 'BEGIN { FS = "\t" } ;{ print $44=strftime("%d %b %Y",$44) "\t" $44 }'
Run Code Online (Sandbox Code Playgroud)
我收到了:
31 12 1969 2012-09-27
Run Code Online (Sandbox Code Playgroud)
但我曾预料到:
27 Sep 2012 2012-09-27
Run Code Online (Sandbox Code Playgroud)
错误在哪里?谢谢.
如果你真的想用awk内置函数转换格式,这个例子可以帮助你:
kent$ echo "2012-09-27" |awk '{t=$0;gsub("-"," ",t);print strftime("%d %b %Y", mktime(t" 00 00 00"))}'
27 Sep 2012
Run Code Online (Sandbox Code Playgroud)
阅读手册页中的以下功能说明:
mktime(datespec)
strftime([format [, timestamp[, utc-flag]]])
Run Code Online (Sandbox Code Playgroud)
编辑尝试修复你的旧命令,但没有输入文件,无法测试它...
awk 'BEGIN {FS=OFS="\t"}{t=$44;gsub("-"," ",t); print strftime("%d %b %Y", mktime(t" 00 00 00")),$44}' test.txt
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
6156 次 |
| 最近记录: |