试试
grep -v -B2 "xxx" test,txt
Miscellaneous:
-v, --invert-match select non-matching lines
Context control:
-B, --before-context=NUM print NUM lines of leading context
过滤结果会包含结果的并集
可以尝试管道符
grep -B2 "xxx" test.txt | grep -v "xxx"