I need to match a pattern in a file AND print the following 2 lines. I am using grep -A2 for this. But I want to ignore some lines from this first grep.
I need the output from the first 'grep -A2' to do some further processing on so piping to grep -v won't help me as far as I understand.
$cat file.txt
stringA-hurdygurdy-andmorechars
line1
line2
stringA-hurdygurdy-stringB-andmorechars
line1
line2
stringA-hurdygurdy-andmorechars
line1
line2
I need to grep -A2 all the lines that have "stringA-hurdygurdy" but not the ones that contain stringB.
I'm trying
grep -A2 ^stringA.*[^stringB].* file.txt