我有一个格式如下的文件:
========================================================
line1line1line1line1line1line1line1line1line1
line2-anything could be here
...anything again
++++++++++++++++++++++++++++++++++++++++++++++++++++++++
========================================================
abc abc abc bacbk kjhhjkh
line2-anything could be here SOME_STRING
...anything again
++++++++++++++++++++++++++++++++++++++++++++++++++++++++
我想用不存在的say来搜索和替换块(在=====*
and之间定义)。例如,上面的文件看起来像:++++*
abc
SOME_STRING
========================================================
abc
++++++++++++++++++++++++++++++++++++++++++++++++++++++++
========================================================
abc abc abc bacbk kjhhjkh
line2-anything could be here SOME_STRING
...anything again
++++++++++++++++++++++++++++++++++++++++++++++++++++++++
因为块 1 没有SOME_STRING
.
我可以使用搜索模式获取块
========================================================\_.\{-\}++++++++++++++++++++++++++++++++++++++++++++++++++++++++
但后来我想 grep 此模式搜索的结果,如果 grep 返回 1(未找到匹配项),请将块替换为abc
.
是否可以?提前致谢。