Replace with sed after the first occurence of specific word - Linux/Ubuntu

时间:2016-04-07 10:38:10

标签: linux bash sed

Original file:

bla bla test
blabla
start
test
blabla
start
test

The result should be:

bla bla test
blabla
start
edit
blabla
start
edit

So after the first occurence of "start" all "test" should be replaced with "edit"

1 个答案:

答案 0 :(得分:2)

You can use this sed:

sed '/start/,$s/test/edit/g' file

bla bla test
blabla
start
edit
blabla
start
edit

Explanation:

/start/,$      # find text from first occurrance of start till end
s/test/edit/g  # in the found text replace test by edit globally