通过开始/结束模式删除文本文件中的行

时间:2019-12-01 11:29:53

标签: unix awk sed replace

我想使用SED的AWK中的以下逻辑从文件中删除行:

  • 找到一条等于变量$ STRING_1的值的行
  • 删除以下几行,直到一行等于变量$ STRING_2的值

例如:

$STRING_1="<<<EOT"
$STRING_2=">>>EOT"

$text="
First line, it will not be removed
Second line

<<<EOT
this block will be removed
including surrounding tags <<<EOT and >>>EOT
>>>EOT

this line will not be removed

<<<EOT
this block will be removed as well...
>>>EOT

End of file which will not be removed :)
"

程序运行应导致$text等于以下值:

First line, it will not be removed
Second line


this line will not be removed


End of file which will not be removed :)

0 个答案:

没有答案