You can make use of grep for this very easily:
$ ls -l test | grep .
ls: cannot access 'test': No such file or directory
This assumes that your grep output is coloured (this is the default on most distros).
This will result in stdout
being highlighted with the default grep colour, for example:
$ (echo "this is stdout"; echo "this is stderr" >&2) | grep .
this is stderr
this is stdout
The first line of output is white while the second is coloured. This might be the opposite of what you want if your default grep colour is red. If you explicitly want to set stdout
to green you could do this to set the grep colours to green:
$ GREP_COLORS='ms=01;32'
$ (echo "this is stdout"; echo "this is stderr" >&2) | grep .
If you explicitly want to get red output for stderr
:
$ GREP_COLORS='ms=01;31'
$ (echo "this is stdout"; echo "this is stderr" >&2) 2> >(grep .)
If you really want both stderr and stdout to be specific colours then you can do this:
$ (echo "this is stdout"; echo "this is stderr" >&2) 2> >(GREP_COLORS='ms=01;31' grep .) 1> >(GREP_COLORS='ms=01;32' grep .)
stderred
in your shell environment'sLD_PRELOAD
to getstdout
andstderr
in different colours. Here's a related question in that vein.