Wil*_*iam 3 sed awk text-processing
我需要从 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
Run Code Online (Sandbox Code Playgroud)
我需要一个带有 sed 范围的解决方案,类似这样:
sed '/string1/,/string2/d' file.txt
关键是我不知道如何延伸/string2/
到与 string2 的第七个匹配相对应的行。理想的输出应该是:
whatever
anything else foo string2
xpto
string2
foo whatever
Run Code Online (Sandbox Code Playgroud)
sed -e:t -e'/string1/!b' -e'/\(.*string2\)\{7\}/d;N;bt'
Run Code Online (Sandbox Code Playgroud)