Ed
替換 ed 中第二次出現的單詞/片語
僅替換 ed 中第二次/第三次出現的單詞/片語的語法是什麼?
He wanted to buy groceries from the shop, but preferred not having to go into the shop. >> He wanted to buy groceries from the shop, but preferred not having to go into it. >>
ed
,中的替換命令在s///
命令字元串的末尾採用零個或多個標誌。如果標誌包含正整數n,則替換將作用於第n次匹配。假設您想
the shop
用 string 替換目前行上第二次出現的 substringit
,因此您將使用s/the shop/it/2
來自編輯會話的快照可能如下所示,其中使用者查看目前行,
p
然後決定對第二次出現的 進行更改,the shop
在編輯後再次顯示該行(使用命令的標誌p
)s///
:p He wanted to buy groceries from the shop, but preferred not having to go into the shop. s/the shop/it/2p He wanted to buy groceries from the shop, but preferred not having to go into it.
s///
編輯命令的這一特性由sed
.