Is there a way to color particular words printed on console based on user preference?

For example I need to color text 'error' when a particular program is compiled.

link|improve this question
feedback

2 Answers

up vote 2 down vote accepted

You'll need to work with the output and some script/alias. Check So You Like Colors for reference of how to use colors in terminal.
Example:

gcc main.c 2>&1 | sed -e 's/\(error\)/^[[1;31m\1^[[m/'

BEWARE: the first ^[ above is a escape sequence, press Ctrl-V + ESC to create them.
I'm redirection 2>&1 stderr to stdout and replacing sed error with error in bold and red color. And finally reseting colors and attributes back to normal ^[[m.

Result in that: example of coloring just error You should setup some script/alias in your ~/.bashrc.

link|improve this answer
2  
Use tput instead of hardcoding the sequences. – Ignacio Vazquez-Abrams Jun 9 '11 at 6:49
tput is owned by ncurses here, if you don't care about one more dependence use tput. – dvd Jun 9 '11 at 13:01
Thank you, I found this also useful - bramschoenmakers.nl/en/node/511 – nimo Jun 9 '11 at 14:16
feedback

That case has probably been already done, see the colorgcc script.

link|improve this answer
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.