Little neat parameter for
grep to show lines before and after the found line.
-A number of lines to show before,
-B number of lines to show after and
-C numbers of lines to show before and after (with default of 2).
$ cat error.log | grep "My error message" -C 5
Excerpt of the documentation:
Print num lines of trailing context after each match. See also the -B and -C options.
Print num lines of leading context before each match. See also the -A and -C options.
Print num lines of leading and trailing context surrounding each match. The default is 2 and is equivalent to -A 2 -B 2. Note: no whitespace may be given between the option and its argument.