Alex Rivera | Logout

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

Asked 2012-10-22T14:53:53.207
25

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.

How can I do this using sed ?

Edit
Report

1 Answer

1

This might work for you (GNU sed):

sed -r 's/^av(pgw)?.*/replacement/;t;s/^/replacement /' file
answered 2012-10-22T15:10:24.153

Your Answer