29/5/09

Highlight text from a command's stdout

It happened to me many times. For example when reading the output of tcpdum and wanting to look at an especific IP but without cutting the context I used to do "| grep --color=auto -C 10 IP".
Or when reading the output of strace and looking for a written file the context is important, so I came up with this:

highlight (){
    if [ -n "$1" ] ; then
        sed "s/$1/\x1b[32;1m&\x1b[1;0m/g" /dev/stdin
    else
        echo "ERROR: What words to highlight?"
    fi

}

Just write it in your .basrc.

For example:
cat .xsession-errors | highlight gnome-panel
Will highlight only "gnome-panel" in green, leaving the output intact.

Some Vista fun...

3 comentarios:

Anónimo dijo...

che si sos tan anti-microsoft porque tenes una direccion de hotmail?

alvare#ClrnD dijo...

Anónimo: Porque el 90% de mis amigos usan MSN para comunicarse en internet, y ser anti-capitalista no significa ser estupido.
No me voy a privar de esas amistades por una tonta direccion.
Gmail es la de verdad, hotmail es para el spam y no recuerdo la ultima vez que entre a la pagina.

Anónimo dijo...

A bien por vos, igual hoy dia ya podrias darla de baja, si podes tener contactos de msn en gmail.