Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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.

share|improve this question
add comment

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.

share|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
add comment

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

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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