linux - How do I use sed for selective replacement of certain lines -


i have text follows in file:

line 1 line 2 word1 line3 line 4 word2 line5 

i replace lines between word1 , word2 produce final output:

line 1 line 2 new lines xxxxx line5 

with sed '/word1/,/word2/d' input.txt can remove lines, how can replace them instead of deleting them?

one way:

replacement text file:

$ cat rep new lines xxxxx 

input file:

$ cat file line 1 line 2 word1 line3 line 4 word2 line5 

sed command:

$ sed '/word1/,/word2/{ > /word2/r rep > d > }' file 

the sed command seraches line range word1 till word2 , deletes lines(d) , , when word2 encounterd, dumps replacement file contents(r rep).


Comments

Popular posts from this blog

SVG stroke-linecap doesn't work for circles in Firefox? -

routes - Laravel 4 Wildcard Routing to Different Controllers -

cross browser - XSLT namespace-alias Not Working in Firefox or Chrome -