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

后端 未结 8 1602
谎友^
谎友^ 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:23

    using posix sed (and a sub shell due to missing time function in sed)

    sed -n "/^Hello/ s/$/ $( date +'%Y-%m-%d' )/p" party.txt
    

    return

    Hello Jacky 2016-11-10
    Hello Peter 2016-11-10
    Hello Willy 2016-11-10
    Hello Mary 2016-11-10
    Hello Wendy 2016-11-10
    

提交回复
热议问题