Outputting colours in HP-UX scripts


 
Thread Tools Search this Thread
Operating Systems HP-UX Outputting colours in HP-UX scripts
# 1  
Old 01-21-2013
Outputting colours in HP-UX scripts

Hi all,

This is my first ever posting, so please be gentle with me Smilie

I'm trying to write a script in HP-UX which outputs text in different colours, but although I can get the script to output different colours to the screen, I can't get it to write different colours to a file. Take the following example:

Code:
 
FGNORMS=$(printf "\033[m")
FGGREEN=$(printf "\033[1;32m")
FGBLUE=$(printf "\033[1;36m")
echo $FGGREEN"Business Unit 9 Totals                  : "$FGNORMS
echo $FGBLUE"Business Unit 9 Totals                  : "$FGNORMS
echo $FGGREEN"Business Unit 9 Totals                  : "$FGNORMS >> testlogfile.txt
echo $FGBLUE"Business Unit 9 Totals                  : "$FGNORMS >> testlogfile.txt

When I run it from my terminal, it outputs:
Code:
Business Unit 9 Totals                  :
Business Unit 9 Totals                  :

where the first line is green, and the second is blue.

The testlogfile.txt, however, shows:
Code:
^[[1;32mBusiness Unit 9 Totals                  : ^[[m
^[[1;36mBusiness Unit 9 Totals                  : ^[[m

with no colours.

Anyone help me please?

Last edited by radoulov; 01-21-2013 at 10:10 AM..
# 2  
Old 01-21-2013
It will output the text colored in desired color (when using cat or alike).

In the file you will find special escape sequences for displaying, in your case, colored text, but it can be used for all sorts of stuff (bold,underline etc.), you won't actually get green text inside the file when you edit it with editor.
# 3  
Old 01-21-2013
Thanks, Peasant, but what file are you referring to? I don't want to edit the output file from my script, just view it.
# 4  
Old 01-21-2013
Then just use cat testlogfile.txt, and should output green text (blue or whatever you set it to), if you edit it with editor you will see your text enclosed in special escape chars as per example above.

Hope that clears things out.

Regards
Peasant.
# 5  
Old 01-21-2013
Hi neilharvey...

Take a look at how I do it here on a default Linux shell/terminal:-

https://www.unix.com/shell-programmin...generator.html

Your first reset esc sequence should read "\033[0m" for a reset to the default colours...

Hope this helps...

---------- Post updated at 02:08 PM ---------- Previous update was at 12:46 PM ----------

Also try this as a starting point...
Code:
# Note double backslash...

printf "\\x1B[1;32;40m Some text...\n" > text.txt

cat text.txt

Hope this is helpful...

Bazza, G0LCU...

Last edited by radoulov; 01-21-2013 at 10:10 AM.. Reason: Code tags!
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

How to change colours in Linux Terminal Xfce?

Hi all - just started using Linux Mint 17 and I need to change the Foreground & Background Colours for the Terminal, my eyesight is not what it used to be many years ago, so any help would be much appreciated. Regards Malcolm (6 Replies)
Discussion started by: electrocad
6 Replies

2. Shell Programming and Scripting

FONT colours

Hi, I have set the following piece of code in .vimrc file. ================================================ if has("terminfo") let &t_Co=16 let &t_AB="\<Esc> ================================================= unable to understand the significance of certain things. This sets the colour... (4 Replies)
Discussion started by: rac
4 Replies

3. Shell Programming and Scripting

To print a line in colours.

Hi all, In my script output, I want to print a line with blue colour, if the condition is satisfied, otherwise it should print with red colour. Can anyone please help me on the same requirment. Thank You. Regards, Raghu. (1 Reply)
Discussion started by: raghu.iv85
1 Replies

4. UNIX for Dummies Questions & Answers

getting input, then outputting it

Hi! I am a newbie to Unix. I was writing a little game program for fun when thought of an idea to allow data to be saved. I knew to take all of the Predefined variables and put them into a separate file, then including the file in the program. But I am having trouble making it so that the user... (0 Replies)
Discussion started by: signebedi
0 Replies

5. Shell Programming and Scripting

Outputting to table

I have information in a file called HITS. This file has been populated by the user entering search criteria. the HITS file contains information: filname.hits: 123.33.345.66 Fri Nov 26 11.45.56.43 GMT 2006 at the moment i am just displayin the information using cat HITS. ... (3 Replies)
Discussion started by: amatuer_lee_3
3 Replies

6. Solaris

putty to change screen colours

Can any one tell me how to change the screen colors of the screen when connected unix using putty. I tryed setting from colors but it's not happening (2 Replies)
Discussion started by: svenkatareddy
2 Replies

7. UNIX for Advanced & Expert Users

How to set background colours for a cygwin console

Hi, I need to set the background colors for cygwin console, when I do ssh to production boxes. This should be done through commands.. Please suggest me asap. Thanks in advance. (3 Replies)
Discussion started by: praveen_b744
3 Replies

8. Shell Programming and Scripting

Can i add colours to bourne Script ?

Can i add colours to bourne Script ? (22 Replies)
Discussion started by: XXXXXXXXXX
22 Replies

9. Shell Programming and Scripting

Colours

There has been a previous question about displaying text in different colours using a script in Bourne - this doesn't seem to work the same for Korn... Is it possible to display text in different colours when using the Korn shell or am I doing it wrong? (3 Replies)
Discussion started by: dbrundrett
3 Replies

10. Post Here to Contact Site Administrators and Moderators

Use of colours.

Any chance you might change the icon's that indicate New/No New Posts in the forum. For those who suffer colour blindness of varrying degrees it has become a bit of a problem (myself included) with the new colour scheme. Cheers, Cameron (4 Replies)
Discussion started by: Cameron
4 Replies
Login or Register to Ask a Question