在UNIX中替换下一个出现的字符串
问题描述:
我是UNIX新手。如何将“the”的下一个单词替换为“there”?在UNIX中替换下一个出现的字符串
我知道s/\<the\>/there/
可以代替行中第一个出现的“the”。教科书上说:n – search forward for the next occurrence of the text searched previously.
但是把“n”放在哪里?
答
把号码末,在那里你会期待g
:
echo "This is the test of replacing the third word the by there" | sed 's/\<the\>/there/3'
This is the test of replacing the third word there by there
看起来像**的** VI编辑指令。只需输入n,然后按回车键即可将光标移至下一个匹配的单词。 –
@ArifBurhan你的意思是我先输入n,然后输入s/\/there /?它不像我预期的那样工作。 –
kzhang12
@ArifBurhan我试着n,然后输入几次。它会将光标移到下一个匹配的单词,但它不会被替换。 – kzhang12