linux – 如何使用sed替换行中的第3个单词
发布时间:2020-12-13 23:56:39 所属栏目:Linux 来源:网络整理
导读:这是我在学习sed过程中的第3篇文章.我有一个假设的要求.我希望能够用’was’替换每行中的第三个单词,其中单词由空格分隔. bash$cat wordshi this is me herehi this is me againhi this is me yet again hi this is me 期望的输出: hi this was me herehi t
这是我在学习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.我尝试了一些执行指令,但没有奏效. Jagrati 我找到了!我找到了! 好的,我终于得到了正确的指示.这有效: sed -e 's/[^ ]*[^ ]/was/3' words 解决方法
如果您不关心格式化,这是一种更简单的方法
$awk '{$3="was"}1' file hi this was me here hi this was me again hi this was me yet again hi this was me (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |