`highlight` command
Sed to the rescue!
You can improve this (as it really need it) but it works pretty well.
$ cat >~/bin/hilight <<EOF
#!/bin/bash
while [ $# -gt 0 ]
do
COMANDO=$COMANDO's/'$1$'/\033[01;'$2$'m\033[K\\0\033[m\033[K/g\n'
shift;shift;
done
sed -e "$COMANDO"
EOF
For sake of simplicity, hilight accepts pair of arguments (first the match, second the color) In this script the attrib is always bold
Read man console_codes (Graphic Rendition) to see color escape secuences, or try this
for attrib in $(seq 0 12); do
for color in $(seq 30 37) $(seq 40 47) $(seq 90 97); do
printf %b " $attrib $color:\033[$attrib;${color}mhi, dudes\033[m"
done
done
It has important drawbacks as using this works:
$ dmesg | hilight \\[ 34 ] 34
but this not at all:
$ dmesg | hilight \\[ 34 ] 34 [[:digit:]] 31
because [:digit:] finds the numbers in the escape secuences on previous sustitutions.
Something like:
$ cat /var/log/kern.log | hilight kernel 31 a 34 et 33
will always work as excepted.
Using time command I found this increments by four the time elapsed, which is not too much.
You can replace sed command with any other parser you like or fits your needs (awk, etc...)
Maybe Radovan Garabík's Generic Colouriser (grc)? It expects a config file as argument and works with regexp's. So not quite without configuration, but you can use process process substitution (<(list)
), so by all means without manual configuration :-)
One can also use egrep with pattern that matches every line on non-printable character, like:
dmesg | egrep --color "swap|$"