替换sed中的多行模式 [英] replacing multiple line pattern in sed
本文介绍了替换sed中的多行模式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我只是想做以下
替换
EXTRATHING {
};
由
SOMETHING {};
在输入文件中.为此,我尝试了
in inputfile. For this, I tried
sed -e 's/EXTRATHING {\n};/SOMETHING/' input_file.txt >outfile.txt
这不起作用.有人可以建议使用 sed 执行此操作的正确方法是什么吗?
This doesn't work. Can someone suggest what would be the correct way of doing this with sed?
推荐答案
sed -n '1h;1!H;${;g;s/EXTRATHING {\n};/SOMETHING {};/g;p;}' input_file.txt
愿意.
问题在于它将整个输入字符串存储在 sed 的缓冲区中.
The problem with this is that it stores the whole input string in sed's buffer.
参见 sed 和多行搜索和替换 了解更多信息和更高效的版本.
See sed and Multi-Line Search and Replace for more info, and a more efficient version.
这篇关于替换sed中的多行模式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文