次のファイルがあるとします。
$ cat test
test line 1
test line 2
line without the search word
another line without it
test line 3 with two test words
test line 4
デフォルトでgrepは、検索語を含む各行を返します。
$ grep test test
test line 1
test line 2
test line 3 with two test words
test line 4
--colorパラメータを渡すと、grep検索式に一致する行の部分が強調表示されますが、式を含む行のみが返されます。grepソースファイルのすべての行を出力する方法はありますが、一致を強調表示しますか?
これを達成するための私の現在の恐ろしいハック(少なくとも10000以上の連続した行が一致しないファイルでは):
$ grep -B 9999 -A 9999 test test

これgrepを達成できない場合、同じ機能を提供する別のコマンドラインツールはありますか?私はをいじりましackたが、オプションもありません。
-C 9999代わりに使用できます-A 9999 -B 9999。常に次のことを行います。grep -C 9999 pattern file