Prepending timestamps to output lines

From Notes_Wiki

Home > CentOS > CentOS 6.x > Server administration tips and tricks > Prepending timestamps to output lines

Sometimes one needs to know how much time a particular command or operation takes. One way of finding out time and CPU consumed by a task is to use time command. But time output will be shown at the end of the command. If command or operation has many intermediate output lines then one can use below described methods to get timestamp prepended to every output line. This way time by which program was able to generate a given output line can be seen.

annotate-output command

annotate-output command prepends current time in front of every output line. Example usage is:

annotate-output ls -l


Passing output to awk to add time-stamps

One can pass the output of command to awk to make it print time-stamps. Syntax for achieving this is:

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


Steps learned from http://stackoverflow.com/questions/21564/is-there-a-unix-utility-to-prepend-timestamps-to-lines-of-text


Home > CentOS > CentOS 6.x > Server administration tips and tricks > Prepending timestamps to output lines