你能用T恤写的每一行加上当前日期和时间的前缀吗?


3

我正在使用'tee'命令将long bash命令的结果捕获到文件中。

我用tee发出的文件能以某种方式在每行前面加上写行的时间戳吗?我正在寻找一种解决方案,其中每一行将具有不同的日期时间值...不是每行前缀相同的值。

我想要这个的原因是,当我通读文件以了解慢速区域的位置时,知道每行何时发出是非常有用的。

Answers:


3

如果发球台不能做某事,请把它送到一个可以做到的程序。moreutils有一个名为ts的工具,其目的恰恰如下:

$ echo test | TS
2月02日13:17:27测试

如果您想为所有内容添加时间戳,则用法应该是显而易见的:

myapp | ts | tee app.log

其他组合是可能的; 例如,仅为时间戳屏幕输出或仅记录日志文件:

myapp | tee app.log | ts
myapp | tee >(ts > app.log)
myapp | tee /dev/tty | ts > app.log
myapp | pee "ts > app.log" "cat"
myapp | pee "cat > app.log" "ts"

(是的,最后一个也来自moreutils。)

By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.