I need to remove the lines corresponding to first 7 occurrences of a string from a txt file in a pattern range (string1-string2).
Example of txt file content:
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
I need a solution with sed ranges, something like that:
sed '/string1/,/string2/d' file.txt
The point is that I don't know how to extend /string2/
until the line corresponding to seventh match of string2. The desirable output should be:
whatever
anything else foo string2
xpto
string2
foo whatever
/string/
makes no sense since/
is the regexp delimiter, not the string delimiter"
- you either meant/regexp/
orindex($0,"string")
(the latter being if you use awk since sed doesn't have any support for string matching).