sed 多行替换 [英] sed multiline replace
问题描述
这是我的示例文本文件:
<前>阿斯达斯//<<<标签这应该被删除//标签>>>这应该在那里//<<<标签吨>阿斯达阿斯达//标签>>>我想要 o/p 为:
<前>阿斯达斯这应该在那里基本上,我试图在//<<>>"(也包括这些行)之间找到行并删除它们.
我尝试使用 sed
<块引用>sed -n'1h;1!H;${;g;s///<<]*TAG>>>//g;p;}'<测试.txt
但是有些方法没有产生正确的输出.包含>"符号的第二个标签在正则表达式中失败.不知道我哪里出错了?
知道怎么做吗?
如果您要删除带有文字文本 'TAG' 的行,请尝试:
<前>sed '///<<根据您的评论,似乎 TAG 可能不是文字,在这种情况下:
<前>sed '/^//<,/^//.*>>/d'这可以通过使用不同的分隔符来简化:
sed '@^//<<<@,@^//.*>>>@d'
this is my sample text file :
asdas //<<<TAG this should be removed //TAG>>> this should be there //<<<TAG T > asd asd //TAG>>>
for which i want o/p as :
asdas this should be there
Basically i m trying to find lines between "//<<>>" (including these lines too) and delete them.
I tried using sed
sed -n '1h;1!H;${;g;s///<<]*TAG>>>//g;p;}' < test.txt
But some how it did not produced correct output. The second tag which contained ">" symbol failed in regex. Not sure where i m going wrong?
Any idea how to do it ?
If you are trying to delete lines with the literal text 'TAG', try:
sed '///<<<TAG/,///TAG>>>/d'
From your comments, it appears that TAG may not be literal, in which case:
sed '/^//<</,/^//.*>>/d'
This can be simplified by using a different delimiter:
sed '@^//<<<@,@^//.*>>>@d'
这篇关于sed 多行替换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!