[英]Replace with sed after the first occurence of specific word - Linux/Ubuntu
原始文件:
bla bla test
blabla
start
test
blabla
start
test
結果應為:
bla bla test
blabla
start
edit
blabla
start
edit
因此,在首次出現“開始”之后,所有“測試”都應替換為“編輯”
您可以使用此sed:
sed '/start/,$s/test/edit/g' file
bla bla test
blabla
start
edit
blabla
start
edit
說明:
/start/,$ # find text from first occurrance of start till end
s/test/edit/g # in the found text replace test by edit globally
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.