How to derive current date and time and append at the end of each line that contains 'Hello'

后端 未结 8 1590
谎友^
谎友^ 2021-02-07 04:08

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         


        
8条回答
  •  情书的邮戳
    2021-02-07 04:16

    gawk (and recent versions of mawk) have a built-in time/date function, so there is no need to use external tools there.

    gawk '/Hello/{print NR " - " $0 " - " strftime("%Y-%m-%d")}' party.txt
    

提交回复
热议问题