When using grep --color=always
I can get pretty color highlighting for regex matches.
However, grep
only returns lines with at least one match.
The way you're doing this now is probably about as clean as you can expect to make this, unless of course you write your own grep tool. If you don't necessarily care about preserving the order of the output, here's the other way I can think of to do this:
function colormatch ()
{
tee - | grep --color=always $1 | sort | uniq
}
Not as efficient as using sed (more processes created, and tee-ing the output), so I'd probably recommend sticking with your sed solution.