how to print current(not stagnant value) with each row using awk (or sed whatever...)

Nils Kassube kassube at
Thu Apr 18 18:34:11 UTC 2013

Rajeev Prasad wrote:
> I am monitoring a log which does not print timestamps, so i am doing
> tail -f on the log, but I want to print time in front of each entry
> as it happend /added in the log. I tried below, but see it has
> problem that it calculates the date value once and use it for all new
> records (which will be on different time added to lgo file)
> OS = solaris 10
> $echo "`date`" >> file1
> $tail -f file1| awk '{print d,$0}' "d=$(date)"
> Thu Apr 18 17:57:18 GMT 2013 Thu Apr 18 17:51:32 GMT 2013
> Thu Apr 18 17:57:18 GMT 2013 Thu Apr 18 17:52:01 GMT 2013

> Please note the 'date' stored in variable d does not change!!!

I don't know awk, so I would use the shell read command like this:

tail -f file1 | while read l;do echo "$(date) $l";done


More information about the ubuntu-users mailing list