【发布时间】:2011-03-17 13:25:05
【问题描述】:
这是我学习 sed 过程中的第 3 篇文章。我有一个假设的要求。我希望能够将每行中的第三个单词替换为“was”,其中单词由空格分隔。
bash$ cat words
hi this is me here
hi this is me again
hi this is me yet again
hi this is me
期望的输出:
hi this was me here
hi this was me again
hi this was me yet again
hi this was me
请大家帮忙看看如何用 sed 来做这件事。我尝试了一些执行指令,但没有奏效。 谢谢,
贾格拉蒂
我找到了!我找到了!
好的,我终于得到了正确的指示。这有效:
sed -e 's/[^ ]*[^ ]/was/3' words
【问题讨论】:
标签: linux shell sed awk replace