Colorize grep automatically – pick a color, any color


Colorize Grep

Using grep syntax highlighting to colorize grep output is great for seeing where grep actually matched your regular expression or simple word on a line.

for x in {28..40}; do export GREP_COLOR=”1;$x;40″; grep Swap /proc/meminfo; echo “1;$x;40″; done

The code above loops through a bunch of color codes, exporting the GREP_COLOR variable for each one and grepping something with that color highlighting from /proc/meminfo, a place all linux users should have available and get output from.
red green and blue color pencils
In my bashrc I use GREP_COLOR in conjunction with GREP_OPTIONS=’–color=auto’ to colorize the output for me without affecting scripts or multiple commands chained together where I don’t want ANSI colors screwing up the output.

Grep Aliases

While we’re on the topic of bashrc, another tweak I throw in is alias’s for misspelled greps. I can’t be the only one that types gerp or hold’s shift too long after a pipe and types Grep accidentally, right?



Posted on November 13th, by admica in Linux, simple.

Leave a Reply

Your email address will not be published. Required fields are marked *


*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">