Is there a way to make all the output of my terminal colored in a personalized way? e.g: If I issue the command: sudo apt-get update - I will get a column of text and what I want is a way to colorize RED if there are any words like "ERROR" in this text, and GREEN any words like "DONE" or "FINISHED".

Thats just an example, and I understand that this could screw up with other programs colored output, just curious if this is possible.

I'm using ZSH at the moment, but accept answers for every terminal emulator.


You can use sed to replace word-boundary-delimited "ERROR", "DONE" and "FINISHED" strings with the same string enclosed in ANSI color escape sequences (you could alias the command in ~/.bashrc for convenience; as you can see this works in Zsh, but since it's the terminal that interprets the escape sequences this would work in any shell running in an ANSI / VT100-compatible terminal):

sudo apt-get update |& sed 's/\bERROR\b/\x1B[1;31m&\x1B[0m/; s/\bDONE\b/\x1B[1;32m&\x1B[0m/; s/\bFINISHED\b/\x1B[1;34m&\x1B[0m/'
sudo apt-get update |&
    sed '


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.