Is it possible to have grep search for multiple expressions, but only colour a specific one of them?
Example of what I'm after:
cat file | grep -e foo --colour -e bar
Output (where bold represents coloured):
foo baz
bar baz
qux foo
foo bar
PCRE can be abused so that there is a match but nothing matched that would be highlighted:
grep -P 'foo.*\K$|bar' input
grep -P '(?=foo)|bar' (which would also work with older versions of PCRE).
A solution (though not particularly elegant) is to use multiple grep queries.
cat file | grep -e foo -e bar | grep -9999 --colour -e bar
Note: The -9999 flag is a hack to get grep to output a lot of lines from stdin. It is possible to increase the value if it is required.
<file grep -e foo -e bar | grep --colour -e '^' -e bar