Sed command : how to replace if exists else just insert?

后端 未结 2 1175
无人及你
无人及你 2021-01-01 16:16

I need to edit several lines in a file such that if a line begins with (av or avpgw) then replace these with new text, else just insert the new text in beginning.

H

2条回答
  •  北荒
    北荒 (楼主)
    2021-01-01 16:52

    This might work for you (GNU sed):

    sed -r 's/^av(pgw)?.*/replacement/;t;s/^/replacement /' file
    

提交回复
热议问题