tips – grep で前後の行も表示させるには

マッチ行直前の行を表示するには -B {行数}(または –before-context={行数})を、直後の行を表示するには -A {行数}(または –after-context={行数}) を指定します。
 
例: sh のマニュアル(manpage)から grep 検索する。
オプションなし(ただし -n は行番号を表示してわかりやすくするため付加しています)

$ man sh | grep -n UNIX
1378: A sh command, the Thompson shell, appeared in Version 1 AT&T UNIX. It
1379: was superseded in Version 7 AT&T UNIX by the Bourne shell, which inher-
1383: Bourne shell from AT&T System V.4 UNIX.

 
直前と直後 1 行ずつ表示

$ man sh | grep -n -A 1 -B 1 UNIX
1377-HISTORY
1378: A sh command, the Thompson shell, appeared in Version 1 AT&T UNIX. It
1379: was superseded in Version 7 AT&T UNIX by the Bourne shell, which inher-
1380- ited the name sh.

1382- This version of sh was rewritten in 1989 under the BSD license after the
1383: Bourne shell from AT&T System V.4 UNIX.
1384-