KSH printf: columns and colors


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting KSH printf: columns and colors
# 1  
Old 07-21-2008
KSH printf: columns and colors

Ih all,

I need to make a ksh script with colors, it is possible with printf to combine column and colors ? i seem not working, I think i dont doing the good thing:

Code:
 printf -n "%-15s %-20s %-20s\n" "\033[01;34m This \033[00m" "\033[01;25mthat \033[00m" "there"

the position is ok

Name______Age________Site
----________---_________----
Bob Actor___30_________Orange County
Toto_______20_________France


Code:
printf "\033[34mColor\033[m \033[25mis\033[m ok

The color is ok
Color is ok


Code:
printf "%-15s %-20s %-20s\n" "Name" "Age" "Site" "----" "---" "----" "\033[34mBob Actor\033[m" "\033[31m30\033[m" "\033[30mOrange County\033[m"

The position is ok but it dont translate the octal color code

Name______Age________Site
----________---_________----
\033[34mBob Actor\033[m \033[31m30\033[m \033[30mOrange County\033[m


where i'm wrong ?

thanks for your help
# 2  
Old 07-21-2008
It is not working because you are using repeated formatting i.e. "%-15s %-20s %-20s\n" The following example shows one way of doing it (I just used one escape sequence to keep it simple).
Code:
printf "%-15s %-20s %-20s\n" "Name" "Age" "Site" "----" "---" "----"
printf "\033[34m"
printf "%-15s %-20s %-20s\n" "Bob Actor" "30" "Orange County"

# 3  
Old 07-22-2008
oh thanks a lot it works fine Smilie

Code:
#!/usr/bin/ksh

printf "%-15s %-20s %-20s\n" "Name" "Age" "Site" "----" "---" "----"
printf "\033[34m"
printf "%-15s" "Bob Actor"
printf "\033[31m"
printf "%-20s" "30"
printf "\033[32m"
printf "%-20s\n" "Orange County"
printf "\033[mo"

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Use stty columns 140 in .profile on ksh

Hi, I am trying to put stty columns 140 in .profile to set column width to 140 so I don't have to manully do it every time. My main goal is to avoid seeing "Terminal too wide" message whenever I try to use vi editor in full screen. I am on korn shell echo $SHELL /bin/ksh So even... (8 Replies)
Discussion started by: pat_pramod
8 Replies

2. Shell Programming and Scripting

awk printf format in columns

Hi all, i have written this script: awk -F';' ' BEGIN { printf "\n" printf "\n" printf "\n" printf "----------------------------------------------\n" print " For test " printf "----------------------------------------------\n" test_200 = 0 test_300 = 0 test_500 = 0 test_1000 = 0... (11 Replies)
Discussion started by: arrals_vl
11 Replies

3. Shell Programming and Scripting

Text Formatting using printf[ksh]

Hi All, I am attempting to create a fixed length tilde delimited file using printf. The variables are initialized to fixed length blank spaces a=' ' b=' ' c=' ' d=' ' Sometimes the variable might contain values and sometimes they are... (5 Replies)
Discussion started by: angie1234
5 Replies

4. Shell Programming and Scripting

Problem with printf in UNIX KSH shell

Hi ALL, I am using SunOS 5.9 and KSH(bin/ksh) The problem am facing is error message diaplyed on screen printf: 12099415.79 not completely converted printf: + expected numeric value printf: 11898578.29 not completely converted When i try printing with The output is... (6 Replies)
Discussion started by: selvankj
6 Replies

5. Shell Programming and Scripting

\n in ksh using echo & printf

#!/usr/bin/ksh var1="Hi World" var2="Morning" var3=$(echo "$var1" \n "$var2") echo $var3 var3=$(printf "$var1 \n $var2") echo $var3 Output Any way to get in my $var3 ? (7 Replies)
Discussion started by: dahlia84
7 Replies

6. Shell Programming and Scripting

ksh questions - Reading columns and lines on unix

1-) For the command below, I want to read second column: 32751. How will I get it ? $ ps -ef|grep deneme U00 32751 22745 0 16:30 pts/1 00:00:00 ksh deneme U00 32762 32132 0 16:30 pts/2 00:00:00 grep deneme 2-) For the command below, how will I read all lines line by line? For... (1 Reply)
Discussion started by: senem
1 Replies

7. Shell Programming and Scripting

Convert from CSV to space padded columns (.ksh)

Hello, Could someone please help me to convert a string(s) of comma separated values into space padded columns in .ksh? ex. 10-21-2008,someword,blah,127.0.0.1,8,3 10-21-2008,randomword,ick,128.0.111.128,1,0 converted to 10-21-2008 someword blah 127.0.0.1 8... (6 Replies)
Discussion started by: WhotheWhat
6 Replies

8. UNIX for Dummies Questions & Answers

Colors in Ksh Script

Hi All, is it poosible to Print the error messages in colors.., i am using KSH..., i have tried the following, echo "\033 Hi This is Sam!!! But, when i tried to redirect in to a log file, i am getting as follows, echo "\033 1 line, 31 characters ^[[34m Hi This is Sikki!!! ^[[0m ... (0 Replies)
Discussion started by: Serious Sam
0 Replies

9. Shell Programming and Scripting

printf command in ksh

Hi, I am very confused with my printf command. Somehow one variable can't line up with others... newstart2 ="Mon Nov 11 01 00:00:00 2002" printf "%-20s" $newstart2 Here is the output: Mon Nov 11 01 00:00:00 2002 It spread out to two lines.. Why? (1 Reply)
Discussion started by: cin2000
1 Replies

10. Shell Programming and Scripting

colors in ksh script

hello! I'd like to print on screen amessage. What can I do to print this message with blue fonts. thanks... (4 Replies)
Discussion started by: hoang
4 Replies
Login or Register to Ask a Question