I think what you're looking for is some kind of sed
script that will surround the words you choose with ANSI Color escape sequences. (hmm... lemme look).
EDIT OK, got it:
Here's an example for outputting "Hello" in dark red:
echo -e "\033[31mHello\033[0m"
What's happening? First of all, I'm using echo -e
so that echo
doesn't convert the slashes into on-screen slashes, but rather reads the escape sequence of \033
as a single escaped character. This is actually just 33 in octal, which is 27 (the ordinal for the ESC key).
So what is really being sent to the screen is something like:
<ESC>[32mHello<ESC>[0m
Which the ANSI display interprets as "first do the command 32m
, output "Hello", and then
do the command 0m
.
In this case, the command 32m
means "set the forground color to 2", and since color #2 is dark red, the "pen" used by the terminal will now be dark red. Which means that from this point onwards, all the text that will be displayed on screen will be dark red.
When we're done outputting the text that supposed to be red, we wish to reset the colors, so we call the command 0m
which resets the colors to normal.
For a list of all the escape codes, look up in [http://en.wikipedia.org/wiki/ANSI_escape_code Wikipedia] or just google for it.
So all your sed script has to do is replace the words you choose with the words surrounded by the colors. For example, to replace the word "Feb" in /var/log/messages
, do the following:
tail /var/log/messages | sed -e "s/Feb/\\o033[31m&\\o033[0m/"
(You might have to do this as root to actually read /var/log/messages
)
All that sed
did was search for the word "Feb" and surround it with the same escape sequence as we used above.
You could expand it to color multiple words:
tail /var/log/messages | sed -e "s/\(Feb\|Mar\|Apr\)/\\o033[31m&\\o033[0m/g"
Which would color "Feb", "Mar", "Apr" - each in dark red.
I hope this gives you some idea of how to do what you need!