[buug] Grep command

Sean Neakums sneakums at zork.net
Fri Sep 19 05:53:16 PDT 2003


"Clarke, John" <John.Clarke at LibertyMutual.com> writes:

> I want to grab data from either side of a matched criteria from grep.
> Any one got any other ideas of a command and if it does work please tell
> me what OS and version and what shell.  Also if anyone does do this how
> do you just get lines below or lines above the match rather than both.

GNU grep has some options that seem do what you want:

$ grep --help
[...]
Context control:
  -B, --before-context=NUM  print NUM lines of leading context
  -A, --after-context=NUM   print NUM lines of trailing context
  -C, --context=NUM         print NUM lines of output context
  -NUM                      same as --context=NUM
[...]
$ grep -2 D testfile
B
C
D
E
F
--
B
C
D
E
F
$ grep --version
grep (GNU grep) 2.5.1
[...]





More information about the buug mailing list