Context-based printing is one of the nice features of grep. When grep finds lines that match the pattern, it prints only the matching lines. We may need to see n lines before or after the matching line. The -B and -A options display lines before and after the match, respectively.
The -A option prints lines after a match:
$ seq 10 | grep 5 -A 3
5
6
7
8
The -B option prints lines before the match:
$ seq 10 | grep 5 -B 3
2
3
4
5
The -A and -B options can be used together, or the -C option can be used to print the same number of lines before and after the match:
$ seq 10 | grep 5 -C 3
2
3
4
5
6
7
8
If there are multiple matches, then each section is delimited by a -- line:
$ echo -e "a\nb\nc\na\nb\nc" | grep a -A 1
a
b
--
a
b