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

w7kew-linux at comcast.net w7kew-linux at comcast.net
Thu Apr 18 19:03:30 UTC 2013


The only way to accomplish that is to change the program that creates 
the log file. There is no way to have awk print out the actual time 
that a log event occurs. 


On 18 Apr 2013 at 11:03, 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
> Thu Apr 18 17:57:18 GMT 2013 Thu Apr 18 17:52:53 GMT 2013
> Thu Apr 18 17:57:18 GMT 2013 Thu Apr 18 17:52:58 GMT 2013
> Thu Apr 18 17:57:18 GMT 2013 Thu Apr 18 17:57:25 GMT 2013
> Thu Apr 18 17:57:18 GMT 2013 Thu Apr 18 17:57:32 GMT 2013
> Thu Apr 18 17:57:18 GMT 2013 Thu Apr 18 17:57:37 GMT 2013
> 
> 
> Please note the 'date' stored in variable d does not change!!!
> 
> I want to print current datetime with each row, as the datetime would be at that moment when row was spitted out from file1
> 
> 
> I would appreciate any help.
> 
> ty.
> 
> 
> -- 
> ubuntu-users mailing list
> ubuntu-users at lists.ubuntu.com
> Modify settings or unsubscribe at: https://lists.ubuntu.com/mailman/listinfo/ubuntu-users

-- 
Best Regards, Keith
w7kew-linux at comcast.net
http://home.comcast.net/kilowattradio/






More information about the ubuntu-users mailing list