How to make grep results colored

colorgrep

I have some output of my program:
# php check.php | grep -E "rule_1|rule_4"

I would like results equaling to rule_1 to be red and results equaling to rule_4 to be blue.

Is this possible, because at this moment, everything is colored red.

Best Answer

Try this:

alias egrep="grep -E --color=never"

alias egrep-grey="   GREP_COLOR='1;30' grep -E --color=always"
alias egrep-red="    GREP_COLOR='1;31' grep -E --color=always"
alias egrep-green="  GREP_COLOR='1;32' grep -E --color=always"
alias egrep-yellow=" GREP_COLOR='1;33' grep -E --color=always"
alias egrep-blue="   GREP_COLOR='1;34' grep -E --color=always"
alias egrep-magenta="GREP_COLOR='1;35' grep -E --color=always"
alias egrep-cyan="   GREP_COLOR='1;36' grep -E --color=always"
alias egrep-white="  GREP_COLOR='1;37' grep -E --color=always"

php check.php | egrep "rule_1|rule_4" | egrep-red "rule_1|$" | egrep-blue "rule_4|$"
Related Topic