1

I have a VERY simple bash script written for my Kali Linux distro so I don't have to run apt-get update, apt-get upgrade, apt-get dist-upgrade, apt-get autoclean, and apt-get autoremove every time I open my laptop. After reading up on the syntax for a few days I still can't get it correct. I'm trying to add something in the script to format the terminal output where it will show "Errors" in RED. Any help would be greatly appreciated in adding something to my script which will show errors in RED for apt-get upgrade output. Thank you in advance.

Just FYI here is my two line script...

apt-get update && apt-get upgrade -y && apt-get dist-upgrade -y && apt-get autoclean -y && apt-get autoremove -y
1
  • I don't know Kali, but on Ubuntu grep highlights matches in red, so using this enclose the script in brackets and append | grep -iE '^|^.*error.*$'. This gives ( apt-get update && apt-get upgrade -y && apt-get dist-upgrade -y && apt-get autoclean -y && apt-get autoremove -y ) | grep -iE '^|^.*error.*$': grep '^' makes sure every line is reported; grep -i '^.* error.*$' matches the whole of every line containing "error" (any case); and grep -E allows both search strings in a single expression.
    – AFH
    Commented Nov 13, 2014 at 19:42

1 Answer 1

1

You can use escape characters to put any colour to a line.

For example:

your command 2>&1 | sed 's/^.*error.*$/^[[31m&^[[0m/g'

2>&1 stderr to stdout.

^[ is the escape character. You can write it with ctrl+v+[ It doesn't work if you copy and paste the command.

Other solution:

your command 2>&1 | sed 's/^.*error.*$/"\\e[31m&\\e[0m"/g' | xargs -L1 echo -e

You can replace [31m with other colour codes.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .