在模式搜索的同一行插入带有sed的文本
发布时间:2020-12-14 01:50:24 所属栏目:Linux 来源:网络整理
导读:例如,如果我有这个文件: The green horse is blue localhostmy pants is dirty localhostyour eyes is so beautiful localhostThe best area is localhost 我希望在每次’localhost’模式搜索后在此文件中添加文本(192.168.25.50). 我不想创建新行 我不想在
例如,如果我有这个文件:
The green horse is blue localhost my pants is dirty localhost your eyes is so beautiful localhost The best area is localhost 我希望在每次’localhost’模式搜索后在此文件中添加文本(192.168.25.50). >我不想创建新行 的确,我的结果必须如此: The green horse is blue localhost 192.168.25.50 my pants is dirty localhost 192.168.25.50 your eyes is so beautiful localhost 192.168.25.50 The best area is localhost 192.168.25.50 很多sed问题都存在,但都有一个特定的上下文,无法解决我的简单和基本问题.我已经可以在同一个文件中的模式之后插入文本但从不在同一行中. 你能解释一下如何在sed命令本身使用的模式的同一行中插入sed命令吗? 解决方法
使用GNU sed:
sed 's/blocalhostb/& 192.168.25.50/' file
如果要“就地”编辑文件,请使用sed的选项-i. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |