Context Line Control (GNU Grep 3.7)
2.1.5 Context Line Control
Context lines are non-matching lines that are near a matching line. They are output only if one of the following options are used. Regardless of how these options are set,
grep never outputs any given line more than once. If the
--only-matching) option is specified, these options have no effect and a warning is given upon their use.
numlines of trailing context after matching lines.
numlines of leading context before matching lines.
numlines of leading and trailing output context.
-Care in use, print
--between groups of lines.
-Care in use, do not print a separator between groups of lines.
Here are some points about how
grep chooses the separator to print between prefix fields and line content:
- Matching lines normally use ‘
:’ as a separator between prefix fields and actual line content.
- Context (i.e., non-matching) lines use ‘
- When context is not specified, matching lines are simply output one right after another.
- When context is specified, lines that are adjacent in the input form a group and are output one right after another, while by default a separator appears between non-adjacent groups.
- The default separator is a ‘
--’ line; its presence and appearance can be changed with the options above.
- Each group may contain several matching lines when they are close enough to each other that two adjacent groups connect and can merge into a single contiguous one.