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




Posted by oDn (84.102.xx.xx) on Tue 21 Nov 2006 at 17:21
Just tried out histring on my handy little 'tail -f /var/log/mail.log' script and I really enjoy the colourful highlighting.

Very handy and flexible tool,

thanks for the tip !

[ Parent | Reply to this comment ]

Posted by Anonymous (62.202.xx.xx) on Wed 22 Nov 2006 at 07:43
You can use multitail to add colors to tail.

[ Parent | Reply to this comment ]

Posted by BackSeat (82.152.xx.xx) on Tue 21 Nov 2006 at 19:15
There's also 'colordiff', which is a little easier to use.

[ Parent | Reply to this comment ]

Posted by POX (156.17.xx.xx) on Thu 23 Nov 2006 at 00:13
There's also:
diff file1 file2 | vless
(vless is a symlink to /usr/share/vim/vimcurrent/macros/less.sh)
diff -u file1 file2 | pygmentize -l diff

[ Parent | Reply to this comment ]

Posted by Anonymous (83.238.xx.xx) on Wed 22 Nov 2006 at 12:59
THe URL to a tarball, you provide, links to a precompiled for FreeBSD binary package, that supposedly won't work on Linux. If you seek for a source tarball point your clients to ftp://ftp.FreeBSD.org/pub/FreeBSD/ports/local-distfiles/roam/misc / or any national FreeBSD mirror, fe.: ftp://ftp.uk.FreeBSD.org/pub/FreeBSD/ports/local-distfiles/roam/m isc/.

You can change "uk" to your local national domain suffix.

[ Parent | Reply to this comment ]

Posted by fmf (82.184.xx.xx) on Thu 23 Nov 2006 at 15:53
I use ccze for my tail. A little too memory hungry, but really effective.

[ Parent | Reply to this comment ]

Posted by Anonymous (217.233.xx.xx) on Sun 17 Dec 2006 at 22:00
I think it is easer to use the emacs grep-find command. Syntax highlighting, mouse click redirects to the file and the line where a match is found, etc.

[ Parent | Reply to this comment ]

Posted by xrat (128.130.xx.xx) on Mon 25 Aug 2008 at 11:34
In fact it's not difficult to do something similar to what has been suggested above (including comments) with 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 ]

Posted by Anonymous (129.21.xx.xx) on Mon 13 Apr 2009 at 22:35
The GRML folks have moved their deb repository. This sources.list entry reflects the move:

deb http://deb.grml.org/ grml-stable main

[ Parent | Reply to this comment ]

Sign In







Current Poll

Will you stick to systemd as the default in Debian?

( 62 votes ~ 1 comments )