txtファイルのパターン範囲(string1-string2)から、文字列の最初の7項目に対応する行を削除する必要があります。
txtファイルコンテンツの例:
whatever
xpto string1 foo2
whatever1
string2
xpto1 another_foo
xpto string2
string2 foo1
whatever
string2 another_xpto
string2 string2
foo xpto string2 whatever
anything else foo string2
xpto
string2
foo whatever
次のsed範囲のソリューションが必要です。
sed '/string1/,/string2/d' ファイル.txt
/string2/
要点は、string2の7番目の一致に対応する行に展開する方法がわからないことです。理想的な出力は次のようになります。
whatever
anything else foo string2
xpto
string2
foo whatever
ベストアンサー1
sed -e:t -e'/string1/!b' -e'/\(.*string2\)\{7\}/d;N;bt'