grep: Context Line Control

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