I would like to do a grep to dig through my code hierarchy and look for the term “x”, but color the results and exclude annoying terms. Right now I do:
grep -Rn --color x * | grep -v -e html -e svn -e test -e doc -e y
The problem is that this loses the matching color because of the pipe. Is there anyway to make this one statement so that the coloring isn’t lost?
Specify
--color=alwaysto preserve color formatting through pipes:And later on if you happen to need to pipe the result into a file and need to remove the escape characters that format color, here’s a nifty sed script you can pipe your results through to remove the escape charaters:
(Note that you need
-Eoption instead of-rfor OS X)