【发布时间】:2016-01-06 22:44:32
【问题描述】:
我是 shell 脚本的新手,并且有一个修改多个文件的请求。我有
输入如下
#this is line1 for file1@abc.com
test line 2
test line 3
this is line4 for file1@abc.com
test line 5
this is line6 for file1@abc.com
需要像这样的输出
#this is line1 for file1@abc.com
test line 2
test line 3
##this is line4 for file1@abc.com
this is line4 for file1@xyz.com
test line 5
##this is line6 for file1@abc.com**
this is line6 for file1@xyz.com
我尝试了以下 sed 命令,但无法获得所需的输出。它不会跳过#line 并附加它。
sed -e "/abc.com/{h;s/^/##/P;x;G; /^#/!s/abc.com/xyz.com/;}" file1
我有什么遗漏吗???
请提供帮助,任何其他建议也将不胜感激。
问候, 桑托什
【问题讨论】:
-
你能更清楚地展示你想要的输出是什么吗?
*是输入的一部分还是所需输出的一部分?您的示例 sed 命令中的任何内容都不会跳过带有前导#的行以进行第一部分工作。 -
Etan - 谢谢,这正是我无法隔离的原因
-
我现在已经相应地修改了输入输出
标签: sed