I was looking for a simple way to colorize text such as output of a tail from within my bash shell. I wanted something simple as KISS, of course.
lwatch seems to be tailored for logfiles. ccze is a bit of overkill. MultiTail while sure a nice tool just did not behave as expected, and one has to define color schemes in separate files.
Luckily, I remembered that it is pretty easy to colorize the shell's prompt or any echo lines. So, I quickly checked if a sed command like
sed -e "s/\(my regex\)/$color\1$resetcolor/g"
actually works if colors are stored in environment variables. And it does :-)
Thus, I wrote a small script mycolorize that allows me to do something like
tail -f procmail.log | mycolorize red '^From: .*' blue '^ Subject: .*'
For details see A simple colorize for the shell
disclaimer & imprint :: copyright :: go to top ::
Discussion
You can use the script to beep when your system load reaches some limit with something like
This would beep when the load is 1 or higher. It's based on the content of
/proc/loadavg
which on Debian systems is something like1.00 0.88 0.48 3/107 28593
.The following would beep every 5 seconds at a load >= 2, and it highlights also the average values for the past 5 and 15 minutes.
You can see I am no friend of blue
Very cool, thanks for sharing this. Just what I was looking for :)
Recently, I converted the sample script to use
sed -r
, and today I fixed a bug with(…)
groups when used in front of\/
. The updated script is available at the end of A simple colorize for the shell. Or download it directly: mycolorize-r.shColout by nojhan is a similar tool to "add colors to a text stream in your terminal". It's written in Python and comes with a bunch of great features such as "256 colors mode, colormaps, themes and source code syntax coloring" (quoting from the homepage) while still keeping the whole thing simple to use.
regex-markup is another program that "performs regular expression-based text markup according to user-defined rules". Rules are stored in separate files. The program is written in C. It supports hierarchical rules.
Supercat "colorizes text based on matching regular expressions/strings/characters. Supercat supports html output as well as standard ASCII text."
nachoparker wrote a simple wrapper around
mycolorize
that uses a preset list of colors: Colorize your stdout with xcol (p. 2017-01-23, a. 2017-01-26, archived 2022-03-31)