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):
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It only takes a minute to sign up.Sign up to join this community
PCRE can be abused so that there is a match but nothing matched that would be highlighted:
grep -P 'foo.*\K$|bar' input
A solution (though not particularly elegant) is to use multiple grep queries.
cat file | grep -e foo -e bar | grep -9999 --colour -e bar
-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.