Highlighting strings in text output with histring
Posted by tong on Tue 21 Nov 2006 at 13:07
Recently there was an article on this site discussing adding colour highlighting to grep. Now we're going to look at a general purpose highlighting tool called histring.
If you like to work in console more than X, and like text tools more than GUI ones then histring is definitely a tool for you!
histring simply highlights strings using ANSI terminal escape codes. It is extremely small and lighting fast. I almost use it everywhere in my script where I need a quick peek into large output. Moreover, you almost don't need to learn it, as its syntax is almost identical to grep.
The following two example will turn you into a histring-pro:
zip -t *.zip 2>&1 | histring -fEi 'warning |bad CRC|error: ' | less
This example will show me the content of my .zip files. More importantly, it will alert me if any of the zip files has any problem.
Once you get used to it, you can't image the life without it.
The following is another nifty alias that I use more often than anything else, to accept output from diff or rcsdiff to highlight diff files:
histring -fE '^Comparing files .*|^diff .*' | histring -c yellow -fE '^\-.*' | histring -c green -fE '^\+.*'
With that, who needs to wait 0.5s for tkdiff? :-)
Also, with that I wrote another alias to compare rcs file version by version. I guess no other diffing tool has such an ability to show how things evolve.
histring is available from the following URL:
Luckily Michael Prokop from grml.org has also created a Debian package for it. The source of the package is available from this mercurial repository.
A Debian package is available through the grml repository (just run run "apt-get update; apt-get install histring" on your grml system):
If you are not using grml, it is still OK, just add the following to your /etc/apt/sources.list and run the above commands:
# main grml repository: deb http://grml.org/repos ./
tong
[ Parent | Reply to this comment ]
[ Parent | Reply to this comment ]
diff file1 file2 | vless
(vless is a symlink to /usr/share/vim/vimcurrent/macros/less.sh)
or
diff -u file1 file2 | pygmentize -l diff
[ Parent | Reply to this comment ]
You can change "uk" to your local national domain suffix.
[ Parent | Reply to this comment ]
[ Parent | Reply to this comment ]
[ Parent | Reply to this comment ]
sed (and a little help of your shell). Basicly, you just need to put colors in variables red=$(tput bold;tput setaf 1) normal=$(tput sgr0)Then you can use them like in
tail -f procmail.log | sed -e "s/\(^From: .*\)/$red\1$normal/"If you are curious I have put together some (more) notes, and I wrote a little bash script mycolorize to simplify the process (and to help me remember;). -- Andreas
[ Parent | Reply to this comment ]
deb http://deb.grml.org/ grml-stable main
[ Parent | Reply to this comment ]
[ Send Message ]
Very handy and flexible tool,
thanks for the tip !
[ Parent | Reply to this comment ]