这是我学习sed的第三篇文章。 我有一个假设的要求。 我希望能够用'was'replace每行中的第3个单词,其中单词由空格分隔。
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
如何根据匹配的关键字段,用另一个文件中的行replace文本文件中的行?
如何使用Unixsorting从tie-break组中挑选最高分值
将文本附加到与Sed现有的第一行
以不规则的间隔计算平均值而不考虑shell脚本中的缺失值?
我find了! 我find了!
好的,我终于得到了正确的指示。 这工作:
sed -e 's/[^ ]*[^ ]/was/3' words
正则expression式:返回parenthensis中的字符
在awk与Umlauts printf不工作
expression式错误中的Windows Grep和Awk无效字符
Sed | awk在匹配下一行后删除行
$ 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
我总是这样做:匹配使用组的第一个和第二个单词,然后用反向引用替换它们。
sed 's/^([^ ]*) ([^ ]*) is/1 2 was/'
这看起来在字边界,而不是只有空白,所以它也有标点符号。 它需要GNU sed :
$ cat words hi this is me here hi this is me again hi this is me yet again hi this is me hi this "is,me $ sed 's/w+(W)/was1/3' words hi this was me here hi this was me again hi this was me yet again hi this was me hi this "was,me
在任何类型的sed中:
sed 's/^([[:blank:]]*[^[:blank:]]{1,}[[:blank:]]{1,}[^[:blank:]]{1,})[^[:blank:]]{1,}(.*)$/1was2/' words
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。