I know many programs use color - (vim, ack, color-ls to name a few) but there are still many cases where you're stuck with black and white.

There are scripts that will color output based on regular expressions (i.e. "make anything that matches 'dog' red") but these must be invoked with pipes - for example: "> cat myfile | color dog red" and this is useless for anything interactive.

What I'm looking for is something that hooks the terminal emulator (or an terminal that actually does this) and colors anything that matches a given regex, independent of the shell or program i'm currently using. If this works with ncurses as well that would be awesome. I have too many monochrome programs and it would be great if I could specify a list of keywords to highlight/color when they appear or are typed.

I use Guake console which probably uses GNOME Terminal, I don't know if GNOME has this feature already.

  • Are you looking for a GUI terminal which you would run under X, or a script/shell which you would invoke in any terminal, for example, over SSH? – Josh Jul 24 '09 at 22:29

Short version is: why, yes, you can pipe output from the shell, like any other program.

From there, you can use whatever you like, like, say

$ bash | sed "$(echo -e "s@dog@\e[31mdog\e[0m@g; s@more here@more here@g;")"

Thought I'd add my 'rainbow'. Enjoy:

for((b=0;$b<8;b++)); do echo -ne "\e[4${b}m4$b : "; \
  for((f=0;$f<8;f++)); do echo -ne "\e[3${f}m3${f}"; done; echo -e "\e[0m"; done

I'm still looking for a linux terminal emulator with this feature, but for those reading this who are on macOS X:

  • Get iTerm2 (you'll want this anyway if you're doing lots of command line work on OS X), go to "Settings > Profiles > Advanced" and then click "Edit" under "Triggers". There you can add a trigger with a regular expression like ^.*\[ERROR\].*$ and set the action to "Highlight text" and the parameter to something like "Red foreground".
  • This is exactly what I'm looking for but on Linux. :/ – DGM Dec 5 '16 at 13:35

I do not have a solution but I have thought about how this kind of program should function. What you are asking is not straightforward.

For example, assume your regular expression is simple "flower". 1. If the terminal output is "f" "lower" we should perform the coloring. Or using an editor we first type "lower" and then go to the beginning of the word and type "f". 2. If the terminal output is "flower" we should cancel the already performed coloring. 3. If the output is slow, say five second delay between all the characters in "flower", we should not annoyingly stop the output, and should be able to immediately perform the coloring.

Either the functionality should be very tightly coupled with the terminal program (like you suggest), checking if any of the specified regular expressions matches the current line and then do the coloring. Or to make it more useful, we could use a program (little bit like /usr/bin/script) that acts like terminal device and keeps track of the screen output, for which it needs to know the terminal behavior very well; in this case we should also be able to redisplay the characters with different color (perform coloring and cancel already performed coloring).

You provide nice little programming idea...


I'm pretty sure KDE Konsole (at least the KDE3 version) could do this, however I don't see the support in KDE4.

You can do something with grep like this:

grep -C 99999 --color <whatever>

This should highlight matches but have so much context as to be the whole file.


There are probably better solutions than this, but you may be able to work something simple out with expect: http://expect.nist.gov/. There are expect libraries available for many other programming/scripting languages if you would rather avoid TCL.

In general, TCL is used for automating interactive programs, but it is possible to make them interactive as well.

I'd give you some code to start with but I haven't used it in quite a while myself.


urxvt with the matcher plugin has this feature, for example if you want to change the foreground of strings that look like movie ip addresses (4x3 digits with dots in between) you can have the following in your .Xdefaults:

URxvt.perl-ext-common: default,matcher
URxvt.matcher.pattern.1: ([0-9]{1,3}[.]){3}([0-9]{1,3})
URxvt.matcher.rend.1: fg7

and it will make that happen. You will need to add more things to it but it works.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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