sed colour change

Hi,
I am trying to write a script which will email a backup report from the server,

The contents of the email will be:

 ---------------------- ---- -- ---- ----- ---- ------- ---- ------- -------
|                      |    |  |    |Chnge|Wkng|       |    |       |       | 
|                      |    |  |    |Tape |Bckp|Write  |Vrfy|Verify |Backup |
|         Date         |Type|Id|No.T|Time |Time|Status |Time|Status |Status |
|----------------------|----|--|----|-----|----|-------|----|-------|-------|
| Fri May 31,2013 02:30|FULL|10|   1|    0| 195| PASSED| 228| PASSED| PASSED|
| Thu May 30,2013 18:45|FULL|10|   1|    0| 195| PASSED| 230| PASSED| PASSED|

I was wondering if there is a way using sed or similar to change the colour of the word Passed to green, and if the backup fails the word failed to red,
eg

 ---------------------- ---- -- ---- ----- ---- ------- ---- ------- -------
|                      |    |  |    |Chnge|Wkng|       |    |       |       | 
|                      |    |  |    |Tape |Bckp|Write  |Vrfy|Verify |Backup |
|         Date         |Type|Id|No.T|Time |Time|Status |Time|Status |Status |
|----------------------|----|--|----|-----|----|-------|----|-------|-------|
| Fri May 31,2013 02:30|FULL|10|   1|    0| 195| PASSED| 228| PASSED| PASSED|
| Thu May 30,2013 18:45|FULL|10|   1|    0| 195| PASSED| 230| PASSED| PASSED|
| Thu May 30,2013 02:30|FULL| 9|   1|    0| 195| PASSED| 229| PASSED| PASSED|
| Wed May 29,2013 18:45|FULL| 9|   1|    0| 195| PASSED| 230| PASSED| PASSED|
| Wed May 29,2013 02:30|FULL| 8|   1|    0| 195| PASSED| 228| PASSED| PASSED|
| Tue May 28,2013 18:45|FULL| 8|   1|    0| 196| PASSED| 230| PASSED| PASSED|
| Tue May 28,2013 02:30|FULL||**BACKUP FAILED**
| Mon May 27,2013 18:45|FULL||**BACKUP FAILED**

You can do that, but the colour change depends on which terminal you use to display the email. Look up "termcap" or "terminfo" ("terminfo" is the more modern one, depending on your system it is preferable) in the man pages and then find out which terminal (emulator) you are using, then use "sed" to insert the respective sequence:

# get these from terminfo
switch_2_white=""....some sequence..."
switch_2_red="....some sequence..."
switch_2_green="....some sequence..."

sed -e 's/PASSED/'"$switch_2_green"'&'"switch_2_white"'/g' \
        s/BACKUP FAILED/'"$switch_2_red"'&'"switch_2_white"'/g' 

I hope this helps.

bakunin

Sorry how did you find that info from terminfo,
I tried man terminfo and termcap but could find it??

If your system has not installed the man pages then slap your systems admin with a sledge hammer. ;-))

You could still use "google" because most man pages are on the web already.

I hope this helps.

bakunin

Sorry the man page for terminfo was ther i just couldnt find anything similar to:

switch_2_white=""....some sequence..."
switch_2_red="....some sequence..."
switch_2_green="....some sequence..."

The sequence you have to fill in depends on the terminal you are using. All the capabilities of all terminals known to the system are in the termcap/terminfo database. Read the manpage of terminfo/termcap about how to retrieve the information necessary, then use this procedure to get the correct (escape-)sequences, then fill these in into the variable definitions. Then, the procedure described above will work.

I cannot tell you more details, because i do not know which terminal you are using and every terminal has its own sequences. You will have to find out your terminal by issuing

echo $TERM

and searching for whatever the system displays as answer in the terminfo or termcap database.

I hope this helps.

bakunin

The plethora of terminal types has, for all intents and purposes, been reduced to a single, standard type. This standard, ISO 6429 (also known as ECMA-48, and formerly known as ANSI X3.64 or VT100), is ubiquitous, and terminals that do not support it are few and far between.

switch_2_red=$'\e[31m'
switch_2_green=$'\e[32m'
default=$'\e[0m'