grep with after-context that does not contain a keyword
Posted
by
ukasz
on Super User
See other posts from Super User
or by ukasz
Published on 2012-07-04T15:28:11Z
Indexed on
2012/07/04
21:18 UTC
Read the original article
Hit count: 246
I want to grep through logs, and gather a certain exception stacktrace but I want to only see those that do not contain certain keywords in --after-context. I do not know in which line in after-context the keyword is.
Simple example - given this shell code:
grep -A 2 A <<EOF
A
B
C
R
A
Z
Z
X
EOF
the output is:
A
B
C
--
A
Z
Z
I'd like the output to be:
A
Z
Z
I want to exclude any match that has 'B' in after-context
How do I do this? Using grep is not a requirement, though I only have access to coreutils and perl.
© Super User or respective owner