$ sed ':a; /Network$/{$!{N;ba}}; s/Network\nAdministrator/System\nUser/g; s/Network Administrator/System User/g' test1
System
User System
User
$ sed ':a; /Network$/{$!{N;ba}}; s/Network\nAdministrator/System\nUser/g; s/Network Administrator/System User/g' guide.txt
This guide is meant to walk you through a day as a System
User. By the end, hopefully you will be better
equipped to perform your duties as a System User
and maybe even enjoy being a System User that much more.
System User
System User
I'm a System User
Compatibility Note: All the above use \n in the replacement text. This requires GNU sed. It will not work on BSD/OSX sed. [Hat
[Hat tip: to Philippos.]
$ sed ':a
/Network$/{
$!{
N
ba
}
}
s/Network\nAdministrator/System\nUser/g
s/Network Administrator/System User/g
' filename
:aThis creates a label
a./Network$/{ $!{N;ba} }If this line ends with
Network, then, if this is not the last line ($!) read and append the next line (N) and branch back to labela(ba).s/Network\nAdministrator/System\nUser/gMake the substitution with the intermediate newline.
s/Network Administrator/System User/gMake the substitution with the intermediate blank.