Grep has the following options that will let you do this (and things like it). You may want to take a look at the man page for more information:
- -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.