How can I highlight the grep
results in different colors (for example, green or red) depending on what's matched?
Currently, I've done this:
grep -H -i "^mail.hostname" WEB-INF/config/mail.props | grep --color=auto -P "\=.*"
which outputs (for example):
WEB-INF/config/mail.props:mail.hostname=localhost
where =localhost
is highlighted. (NOTE -- I would like the =
sign NOT to be highlighted, but that's another story.)
How can I get the highlight to be in green when it's localhost
and in red for any other values (such as, for example, smtpserver
)?
UPDATE -- Answer to first 2 comments:
If I do:
grep -H -i "^mail.hostname" WEB-INF/config/mail.props \
| GREP_COLOR='01;31' grep --color=auto -P '=\K.*' \
| GREP_COLOR='01;32' grep --color=auto -P '=\Klocalhost'
the line will only be printed (with highlight in green) when it matches localhost
... Not the expected result...