Show lines before and after with grep
Little neat parameter for grep
to show lines before and after the found line. -A
number of lines to show after, -B
number of lines to show before and -C
numbers of lines to show before and after (with default of 2).
$ grep -C 5 "My error message" error.log
Excerpt of the documentation:
-A num
Print num lines of trailing context after each match. See also the -B and -C options.
-B num
Print num lines of leading context before each match. See also the -A and -C options.
-C [num]
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.