esio
esio

Reputation: 1682

redirect command output with awk

I need redirect output to file and add datetime. 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 remove "> file" on the screen i seen correct output. But I will redirect this to file.

Can anybody help me?

Upvotes: 4

Views: 2635

Answers (1)

anubhava
anubhava

Reputation: 785256

Try tee command like this:

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

tee will display output on STDOUT and store the output in file as well.

Upvotes: 6

Related Questions