ANSI to colorize logs

Ansi color revival to analyze logs


Show in blue the lines containing “[sd” showing everything else and without repeating the same line. (In this example USB sticks)

dmesg| awk '/\[sd/ {print "\33[34m" $0 "\33[39m";next}1'


Show green lines when something is added to udev and red when it is removed:

cat /var/log/udev |awk ' /add/{ print "\33[32m" $0 "\33[39m"} /remove/{print "\33[31m" $0 "\33[39m"}'

The colors follow the ANSI color table.
31 is red
32 is green
33 is yellow but I’m not using it as a color, I’m using \33 and it is the scape character.
34 is blue
39 is white

Using 41 instead of 31 is like using a red Stabilo marker.
they can me mixed. example \33[1;31;43m and \33[0;39;40m

Never use ANSI coloring with logs conected to the internet or unknown users as a priveleged user. ANSI can be used to change keymaps to run commands (ej: the enter key, the up arrow key… to rm -rf /* )
This is not a new security issue and has been used and abused since de BBS era/ 80’s).