Full-Context Highlighted Search With egrep

Ever wanted to search for a pattern using grep but wanted to see all of the content surrounding it as well? The -A and -B options work ok for this purpose, but since we can see color, we can just highlight pattern matches in this fashion:

$ egrep --color 'pattern|$'

A simple example. This generates a random integer every second and highlights any occurance of 1, 2, or 3:

$ while true; do echo $RANDOM; sleep 1; done | egrep --color '[123]+|$'

I find this technique useful for looking through logs or source code.

Dialogue & Discussion