簡體   English   中英

在特定單詞首次出現后用sed替換-Linux / Ubuntu

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM