For colourizing the output of command or contents of a file, I can think of two easy methods that may work well:
grep
- it can be made to show the rest of the file as well, and do multiple matches with a few advanced options - for example:
grep --color -iE 'log|kernel' -C 999
grep --color -iE 'log|kernel|$'
The first searches for log
and kernel
case-insensitively, and shows the surrounding 999 lines. The second searches for log
, kernel
and a character present in every line (as suggested here) case-insensitively. For more info you may be able to consult man grep
if it available, or read the manual for GNU grep or OSX grep.
python-pygments
- should be available via pip
. Can be used for syntax highlighting, it may have a lexer available for what you want to process.
Also, for generally formatting output, you may be able to use ANSI escape codes - e.g:
echo -e "\033[31mred\033[0m"
echo -e "\033[34mblue\033[0m"
The \033
is a escape character, and after that you can specify codes to do different things - you can specify multiple ones as well:
echo -e "\033[1;31mbold red\033[0m"
echo -e "\033[4;34mblue underlined\033[0m"
I'm not sure about support on OSX though... you may need to try a different escape character - colors in the terminal may also need to be enabled.