colourize

This script is an example that shows how to colour the warnings and errors in compiler output in bash. This makes it easier to pick out error messages in the output stream. Adjust the regular expressions to match your use case:

#!/bin/bash
set -e

ccred=$(tput setaf 1)
ccyellow=$(tput setaf 3)
ccgreen=$(tput setaf 2)
cccyan=$(tput setaf 6)

ccend=$(tput sgr0)

sed \
  -e "s/\(.*[wW]arning:\)\(.*\)/$ccyellow\1$ccend\2/" \
  -e "s/\(.*[eE]rror:\)\(.*\)/$ccred\1$ccend\2/" \
  -e "s/make\[[0-9]*\]: .*/$cccyan&$ccend/" \
  -e "s/make.*Error.*/$ccred&$ccend/" \
  -e "s/.*:[0-9]*.*: \*\*\* .*/$ccred&$ccend/" \
  -e "s/^Building.*/$cccyan&$ccend/" \
  -e "s/^generating.*/$cccyan&$ccend/" \
  -e "s/^making.*/$cccyan&$ccend/" \
  -e "s/\(.*[Cc]omplete.*\)/$ccgreen\1$ccend/" \
  -e "s/^Warning.*/$ccyellow&$ccend/"

Usage

 $ make

becomes

 $ make 2>&1 | colourize
colourize.txt ยท Last modified: 2017/12/06 11:18 (external edit)