“当前时间"输出为零 [英] "Current time" outputs as zero
本文介绍了“当前时间"输出为零的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试从file1
输入到file2
,以便file2
中的每一行是每条file1
行的第一字段,后跟一个空格和当前时间.
I am trying to input tofile2
from file1
so that each line in file2
is the first field of each file1
line, followed by a space and the current time.
例如
IN-X_4096_20140802_121306_007 `random text`
IN-X_4096_20140802_133431_012 `random text`
IN-A_6046_20130613_165426 `random text`
IN-A_6046_20130613_165426 `random text`
IN-X_4096_20140802_133431_014 `random text`
成为
IN-X_4096_20140802_121306_007 14:24:32
IN-X_4096_20140802_133431_012 14:24:32
IN-A_6046_20130613_165426 14:24:32
IN-A_6046_20130613_165426 14:24:32
IN-X_4096_20140802_133431_014 14:24:32
但是我得到的是
IN-X_4096_20140802_121306_007 0
IN-X_4096_20140802_133431_012 0
IN-A_6046_20130613_165426 0
IN-A_6046_20130613_165426 0
IN-X_4096_20140802_133431_014 0
我正在使用的代码是:
awk '{b=$1" "date +"%r"; print b >"file2.csv" }' file1.csv
当我使用%T"时也会发生同样的事情
The same thing happens when I use "%T"
推荐答案
从您的问题尚不清楚您期望的是哪种行为,但这是两种Gnu awk解决方案:
From your question it is not clear which behaviour you are expecting, but here are two Gnu awk solutions:
-
在整个命令运行期间,计算出的日期时间字符串必须恒定:
The computed date-time string has to be constant during the entire run of the command:
awk 'BEGIN{t=strftime("%r")}{ print $1,t }' file1.csv > file2.csv
计算出的日期时间字符串必须每行更新:
The computed date-time string has to be updated per line:
awk '{ print $1,strftime("%r") }' file1.csv > file2.csv
这篇关于“当前时间"输出为零的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文