share my experience: highlight parts of a text file that matches a regular expression

Zhang Weiwu zhangweiwu at realss.com
Wed Jun 6 14:52:17 UTC 2007


Dear list

I'd like to highlight part of output of one application that matches a
regular expression. First I thought this is simple:

$ my_app | grep --color=auto 'regexp'

This method have a big problem that lines doesn't match regexp is not
displayed, in my case I want all output of my_app being displayed, only
the matching part highlighted.

First I thought grep might have a parameter to output everything it
receive, and it seems it doesn't. And I discovered I can use '-e'
parameter for this purpose:

$ my_app | grep --color=auto -e 'regexp' -e '$'

The second -e makes all line matched.

Maybe useful for some newbies.
-- 
Zhang Weiwu
Real Softservice
http://www.realss.com
+86 592 2091112



More information about the freebsd-questions mailing list