Awk redirect command output

I need to redirect the output to a file and add the date and time. I try this:

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

I expect:

 2011-12-13 15:00:50 compilation.... 2011-12-13 15:00:52 still compilation 2011-12-13 15:00:55 compilation ... 

How can i do this? If I delete the "> file" on the screen, I see the correct output. But I will redirect this to a file.

Can someone help me?

+4
source share
1 answer

Try the tee command as follows:

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

tee will map the output to STDOUT and save the output to a file.

+5
source

Source: https://habr.com/ru/post/1386111/


All Articles