Using printf to center


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Using printf to center
# 1  
Old 04-19-2005
Question Using printf to center

I created a c-shell script to make a mysql report (I'm new to both scripting and mysql) and I want it to look good so I want to center my header. I am guessing printf is the way to go but I cant figure how. I'd appreciate if somehow would let me know if there is a way to do this. Thanks
# 2  
Old 04-19-2005
see man printf. printf has alot of conversions that work with it. You can pad the left hand side with spaces, use a series of \t to tab, etc. See the man page and you will have both an explanation and examples.
# 3  
Old 04-19-2005
This how you would do it in bash or ksh...
Code:
title="Your title goes here"
printf "%*s\n" $(((${#title}+$COLUMNS)/2)) "$title"


Last edited by Ygor; 04-19-2005 at 10:27 PM..
Login or Register to Ask a Question

Previous Thread | Next Thread

6 More Discussions You Might Find Interesting

1. Solaris

Ops Center AI wrong IP

Hello, I have problems with Automated Installer on Solaris 11. I tried provision Solaris 11 on my T5-1B server from Ops Center, but AI set wrong IP address for manifest SMF. My Ops Center server has two IP addresses 10.236.102.219 and 10.226.21.141. Second IP is in subnet for provisioning of... (25 Replies)
Discussion started by: olibertu
25 Replies

2. Shell Programming and Scripting

How to center output

Hi, i wrote a script which prints me the results of a galton board, everything's fine and it works, but now i want to center the output on the screen and i don't know how to do it.:confused: for i in $(eval echo {1..$SLOT}) do # print all... (3 Replies)
Discussion started by: Don_Bilbo
3 Replies

3. Solaris

Sun Ops Center

Hi, Can anyone share the link to download sun ops centre i have sun partner account, but i unable find the link Thanks RJS (3 Replies)
Discussion started by: rajasekg
3 Replies

4. Solaris

Sun Management Center 4.0

I need to create a managed job to monitor disk space on /tmp for db servers. How do you create a task in SMC to accomplish this? (1 Reply)
Discussion started by: soupbone38
1 Replies

5. Shell Programming and Scripting

Trying to center my output text

Im stumped on how to center the output of my echo command. I also would like to center my calender too, but is the command to center the same for echo and cal? (3 Replies)
Discussion started by: bri4nd4h3r0
3 Replies

6. Shell Programming and Scripting

PrintF and AWK => Center Alignment?

Alright, I'm relativly new to the Unix enviroment and C in general. I'm writing a script for AWK to search through a file and return what it finds with a center alignment, but so far, I can't get it to work. If anyone could help me out, I'd really appreciate it. (1 Reply)
Discussion started by: Mavrick3020
1 Replies
Login or Register to Ask a Question