sed colour change


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting sed colour change
# 1  
Old 05-31-2013
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:

Code:
 ---------------------- ---- -- ---- ----- ---- ------- ---- ------- -------
|                      |    |  |    |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
Code:
 ---------------------- ---- -- ---- ----- ---- ------- ---- ------- -------
|                      |    |  |    |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**

# 2  
Old 05-31-2013
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:

Code:
# 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
# 3  
Old 05-31-2013
Sorry how did you find that info from terminfo,
I tried man terminfo and termcap but could find it??
# 4  
Old 05-31-2013
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
# 5  
Old 05-31-2013
Sorry the man page for terminfo was ther i just couldnt find anything similar to:

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

# 6  
Old 05-31-2013
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

Code:
echo $TERM

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

I hope this helps.

bakunin
# 7  
Old 06-03-2013
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.

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

Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. AIX

putty background colour change in vi editor

Hello, I have a problem with my putty session when i use the vi editor or when i do dbaccess on an Informix database. Suddenly the background and foreground colour of my terminal change and it makes it difficult for me to see whats on the screen. Why this is happening? Is there a way to keep... (2 Replies)
Discussion started by: omonoiatis9
2 Replies

2. Programming

Cshell help with change colour in print

i want to ask how to change the colour of prompt message from use? and also how to change colour in printing........ i want to change it as blue colour and red colour, but i found many website still don't know how to do. how's the command is wrote? thz really!! (1 Reply)
Discussion started by: wendy1089
1 Replies

3. UNIX for Advanced & Expert Users

To change the colour of the content in email sent through unix

Hi I want to change the color of the email content sent through unix. I tried a lot and left in vain. I heard that it could be done by sending the email as HTML. But I don't how to do it. Can you all share your ideas? ~sakthifire (1 Reply)
Discussion started by: sakthifire
1 Replies

4. HP-UX

hpux top colour

Hello, is there some way to change b/w colour of top command output in hpux B.11.31 ? (1 Reply)
Discussion started by: tonijel
1 Replies

5. Shell Programming and Scripting

ksh, font colour

hi all, how do i change the colour of text if i am using printf ?? in my script i am printing out response times from the server and i wanted to print out the max response time in red. ta. (1 Reply)
Discussion started by: cesarNZ
1 Replies

6. HP-UX

How to change font and colour in mail sent from Unix

Dear All, We have following code to send mails from unix to users. We want to see few sentences of mail in bold font or to hightlight few lines in different colours. Could you please let me know how can we do it in function construct_body. ... (3 Replies)
Discussion started by: yogichavan
3 Replies

7. Shell Programming and Scripting

How to change the font colour in unix ?

Could you pls tell me how to change the font colour in unix ? What is the syntax ? (3 Replies)
Discussion started by: sars
3 Replies

8. Shell Programming and Scripting

VT100 terminal and colour

Good day all I am looking for a way to change colours in a text file that get tailed. I have tried using tput, however this does not seem to work. terminal type is using putty and vt100 emulation. Any ideas. :rolleyes: Thanks J (6 Replies)
Discussion started by: jhansrod
6 Replies

9. UNIX for Dummies Questions & Answers

HOw to change the text colour through shell script?

Hi all, I have written one script. If i run the script, particular text in that script needs to be displayed in color.how this could be done?any commands r there to change the colour of the text while running the script? Ur help is appreciated !!! Thanx in Advance, Sona. (7 Replies)
Discussion started by: Sona
7 Replies
Login or Register to Ask a Question