Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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
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.

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
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 - – nimo Jun 9 '11 at 14:16

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

share|improve this answer

Your Answer


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.