想要使用Gawk Bash添加游戏机输出的时刻毫秒
我正在使用以下片段将时间戳添加到控制台输出中
command | gawk '{ print strftime("[%Y-%m-%d %H:%M:%S]"), $0 }'
如何向其添加毫秒?
I am using following snippet to add timestamp to console output
command | gawk '{ print strftime("[%Y-%m-%d %H:%M:%S]"), $0 }'
how to add milliseconds to it?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
为什么不一个简单的bash解决方案?您可以使用
date
命令读取每行,并在时间戳记中进行预示例,例如使用/输出
示例
timestamped output :(
注:谢谢您@jhnc for GNU
date
%03N
specifier)带有bash您还可以使用 process替换来喂食时间戳循环,例如
Why not a simple bash solution? You can read each line and prepend a timestamp using the
date
command, e.g.Example Use/Output
Sample lines:
Timestamped output:
(note: thank you @jhnc for the GNU
date
%03N
specifier)With bash you can also use process substitution to feed the timestamp loop, e.g.
返回原始
日期
想法:Coming back to the original
date
idea:@RoHit:除非我缺少
gawk
手册中的东西,否则我看不到它,除非您要使用gawk
Extensiontime
。否则,这就是我为我的各种awk
s获得microsecs
的方式:它只有53位的精度(或52,取决于您的身份询问隐含的位),所以这些额外的小数点仅仅是错觉
“ substr() “这里既不输出任何东西,也不影响返回的内容。它的唯一功能是充当各种临时分期
|
也就是说,如果您不受
仅限gawk的要求
,我知道awk
的1个变体提供了MilliSec Times而不会外部的时间:@Rohit : unless I'm missing something from the
gawk
manual, I don't see it, unless you want to use thegawk
extensiontime
. Otherwise, this is how I getmicrosecs
for my variousawk
s :It only has 53-bit of precision (or 52, depending on who you ask about the implied bit), so those extra decimal points are mere optical illusions
The "substr()" here neither outputs anything nor affect what's being returned. It's sole functionality is to act as a temporary staging area of sorts
|
That said, if you aren't constrained by
gawk-only requirement
, i'm aware of 1 variant ofawk
that offers millisec times without going external :