テキストと中かっこを含む複数行を削除する

テキストと中かっこを含む複数行を削除する

次の内容を含む複数のファイルがあります。

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
}

段落を削除する必要があります。

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

中括弧の間の行は異なる場合があります(行数が少ないか多い)。私は次のことを試しました。

sed -i 's|This is a test2 *.* !}||g' *

そして

sed -i 's|This is a test2, !}||g' *

しかし成功はありません。

ベストアンサー1

何について

sed -e '/this is a test2/,/}/d'

オリジナル

  • -esedに次のパターンを使用するように指示する
  • /this is a test2/,/}/this is a test2間の線を選択してください。}
  • d削除

使用法

 sed -e '/this is a test2/,/}/d' A > B
  • AファイルからBファイルへのsedの適用

    sed -i  -e '/this is a test2/,/}/d' A
    
  • Aで直接編集

おすすめ記事