I have the following file party.txt
that contains something like the following:
Hello Jacky
Hello Peter
Bye Johnson
Hello Willy
Bye Johnny
Hello Mar
One way using awk
:
awk -v date="$(date +"%Y-%m-%d %r")" '/Hello/ { print $0, date}' party.txt
Results:
Hello Jacky 2012-09-11 07:55:51 PM
Hello Peter 2012-09-11 07:55:51 PM
Hello Willy 2012-09-11 07:55:51 PM
Hello Mary 2012-09-11 07:55:51 PM
Hello Wendy 2012-09-11 07:55:51 PM
Note that the date value is only set when awk
starts, so it will not change, even if the command takes a long time to run.