2016-03-04 80 views
0

我是UNIX新手。如何将“the”的下一个单词替换为“there”?在UNIX中替换下一个出现的字符串

我知道s/\<the\>/there/可以代替行中第一个出现的“the”。教科书上说:n – search forward for the next occurrence of the text searched previously.

但是把“n”放在哪里?

+0

看起来像**的** VI编辑指令。只需输入n,然后按回车键即可将光标移至下一个匹配的单词。 –

+0

@ArifBurhan你的意思是我先输入n,然后输入s/\ /there /?它不像我预期的那样工作。 – kzhang12

+0

@ArifBurhan我试着n,然后输入几次。它会将光标移到下一个匹配的单词,但它不会被替换。 – kzhang12

回答

0

把号码末,在那里你会期待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 
+0

当我输入回声“这是在那里替换第三个词的测试” sed's/\ /there/3'我得到了E518:未知选项:'s/\ /there/3'。如果我输入'/ \ /there/n',它仍然不起作用。 – kzhang12

+0

我正在使用putty.exe,一个老师推荐的工具。 – kzhang12

+0

使用putty可以连接到unix服务器。它取决于该服务器上的软件支持'sed'中的哪些命令。也许你有一个错误的'sed'版本。我的'sed --version'给出了'GNU sed version 4.1.5'。我想你会有另一个'sed'版本。 –

相关问题