I have a large file and a list of my specific strings. The output should not contain my specific lines and one more after each of them. 2 consecutive matches are impossible due to structure of file that i want to filter. For example,
Specific lines:
'ggg'
'sss'
Input:
'ggg'
'123'
'rrr'
'321'
'sss'
'666'
Output:
'rrr'
'321'
Simple grep -v -A 1
does not work
Best Answer
Assumptions:
awk
script)General approach:
Sample input file:
Sample set of lines to match on (and ignore):
NOTE: comments do not exist in files
One
awk
idea:This generates:
NOTE: if assumptions are wrong and/or this does not work for OP's actual files then we'll need the question updated with a more representative set of data
OP has added a comment stating consecutive line matches cannot occur. This allows us to simplify the code a bit:
If we remove one of the
'xxx'
lines from theinput
file this will generate: