使用awk重定向命令输出

esi*_*sio 4 linux awk

我需要将输出重定向到文件并添加日期时间.我试试这个:

make all | awk '{ print strftime("%Y-%m-%d %H:%M:%S"), $0; }' > file
Run Code Online (Sandbox Code Playgroud)

我预计:

2011-12-13 15:00:50 compilation....

2011-12-13 15:00:52 still compilation

2011-12-13 15:00:55 compilation

...
Run Code Online (Sandbox Code Playgroud)

我怎样才能做到这一点?如果我在屏幕上删除">文件",我看到正确的输出.但我会将其重定向到文件.

有谁能够帮我?

anu*_*ava 6

尝试这样的tee命令:

make all | awk '{ print strftime("%Y-%m-%d %H:%M:%S"), $0; }' | tee file
Run Code Online (Sandbox Code Playgroud)

tee将在STDOUT上显示输出并将输出存储在文件中.