删除带有文本和大括号的多行

Tsv*_*nov 3 sed awk

我有多个文件,其中包含以下内容:

this is a test1
 {
test 123
test 456
test 789
}

this is a test2
 {
test 123
test 456
test 789
}

this is a test3
 {
test 123
test 456
test 789
}
Run Code Online (Sandbox Code Playgroud)

需要删除一段:

this is a test2
 {
test 123
test 456
test 789
}
Run Code Online (Sandbox Code Playgroud)

大括号之间的行可能不同(更少或更多行)我尝试过类似的方法:

sed -i 's|This is a test2 *.* !}||g' *
Run Code Online (Sandbox Code Playgroud)

sed -i 's|This is a test2, !}||g' *
Run Code Online (Sandbox Code Playgroud)

但没有成功

Arc*_*mar 5

关于什么

sed -e '/this is a test2/,/}/d'
Run Code Online (Sandbox Code Playgroud)

基本上

  • -e告诉 sed 使用下一个模式
  • /this is a test2/,/}/选择this is a test2和之间的线}
  • d删除它

用法

 sed -e '/this is a test2/,/}/d' A > B
Run Code Online (Sandbox Code Playgroud)