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
This solution should work with any awk:
awk '/Hello/ {cmd="(date +'%H:%M:%S')"; cmd | getline d; print d,$0; close(cmd)}' party.txt
The magic happens in close(cmd)
statement. It forces awk
to execute cmd
each time, so, date would be actual one each time.
cmd | get line d
reads output from cmd
and saves it to d
.