仅替换 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 中第二次/第三次出现的单词/短语的语法是什么?
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
,因此您将使用来自编辑会话的快照可能如下所示,其中用户查看当前行,
p
然后决定对第二次出现的 进行更改,the shop
在编辑后再次显示该行(使用命令的标志p
)s///
:s///
编辑命令的这一特性由sed
.