Q:

grep with after-context that does not contain a keyword

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.

A:

This problem is a good fit for awk:
 grep -A2 A LOG_FILE | awk -v RS='--\n' '!/B/ { printf "%s", $0 }'

`-v RS='--\n' sets the record separator.
!/B/ finds records that do not contain B.

