Outputting colours in HP-UX scripts | Unix Linux Forums | HP-UX

  Go Back    


HP-UX HP-UX (Hewlett Packard UniX) is Hewlett-Packard's proprietary implementation of the Unix operating system, based on System V.

Outputting colours in HP-UX scripts

HP-UX


Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 01-21-2013
neilharvey neilharvey is offline
Registered User
 
Join Date: Jan 2013
Last Activity: 21 January 2013, 6:36 AM EST
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Outputting colours in HP-UX scripts

Hi all,

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

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 09:10 AM..
Sponsored Links
    #2  
Old 01-21-2013
Peasant's Avatar
Peasant Peasant is offline
Registered User
 
Join Date: Mar 2011
Last Activity: 17 April 2014, 9:05 AM EDT
Posts: 607
Thanks: 16
Thanked 137 Times in 133 Posts
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.
Sponsored Links
    #3  
Old 01-21-2013
neilharvey neilharvey is offline
Registered User
 
Join Date: Jan 2013
Last Activity: 21 January 2013, 6:36 AM EST
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
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
Peasant's Avatar
Peasant Peasant is offline
Registered User
 
Join Date: Mar 2011
Last Activity: 17 April 2014, 9:05 AM EDT
Posts: 607
Thanks: 16
Thanked 137 Times in 133 Posts
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.
Sponsored Links
    #5  
Old 01-21-2013
wisecracker's Avatar
wisecracker wisecracker is offline
Registered User
 
Join Date: Jan 2013
Last Activity: 17 April 2014, 5:16 AM EDT
Location: Loughborough
Posts: 491
Thanks: 100
Thanked 97 Times in 84 Posts
Hi neilharvey...

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

http://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 09:10 AM.. Reason: Code tags!
Sponsored Links
Closed Thread

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
FONT colours rac Shell Programming and Scripting 4 06-01-2012 01:34 AM
To print a line in colours. raghu.iv85 Shell Programming and Scripting 1 09-13-2009 02:43 AM
putty to change screen colours svenkatareddy Solaris 2 03-17-2008 12:53 AM
Colours dbrundrett Shell Programming and Scripting 3 02-22-2002 04:21 AM
Use of colours. Cameron Post Here to Contact Site Administrators and Moderators 4 12-12-2001 09:36 AM



All times are GMT -4. The time now is 11:27 AM.