How to center output


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to center output
# 1  
Old 08-28-2012
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.Smilie
Code:
for i in $(eval echo {1..$SLOT})
do                                                # print all elements of the array
  printf "%4d" ${Slots[$i]}    
done

thanks for your help Smilie


Moderator's Comments:
Mod Comment How to use code tags

Last edited by Franklin52; 08-28-2012 at 05:41 AM.. Reason: Please use code tags for data and code samples
# 2  
Old 08-28-2012
Show an example of your plain output and the expected formatted output. Use code tags when doing so.
# 3  
Old 08-28-2012
input: 12 rows and 100 balls
Code:
galton.sh 12 100

   ___ ___ ___ ___ ___ ___ ___ ___ ___ ___ ___ ___ ___ ___ ___ ___ ___ ___ ___ ___ ___
  |   |   |   |   |   |   |   |   |   |   |   |   |   |   |   |   |   |   |   |   |   |
   1   2   5   8  13  19   9  16  12   4   5   4   1
  |___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|
                                          |   |

and it should look like this:

Code:
   ___ ___ ___ ___ ___ ___ ___ ___ ___ ___ ___ ___ ___ ___ ___ ___ ___ ___ ___ ___ ___
  |   |   |   |   |   |   |   |   |   |   |   |   |   |   |   |   |   |   |   |   |   |
                    1   2   5   8  13  19   9  16  12   4   5   4   1
  |___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|
                                          |   |

# 4  
Old 08-28-2012
so something like :
Code:
galton.sh 12 100 | awk -v col=$COLUMNS '{n_blank=(col-length($0))/2 ; printf "%-*s",n_blank," " ;print $0}'

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

Center output of 'cal' command in terminal

I have a function to center output in a terminal. However It only works for variables. I would like to center the output of the command 'cal' or 'cal -3' in a terminal. I have tried: center `cal` CAL=`cal`; center $CAL cal > cal.txt; center `cat cal.txt` center "`exec cal`" To no avail,... (10 Replies)
Discussion started by: AlphaLexman
10 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

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 Replies)
Discussion started by: CSGUY
2 Replies
Login or Register to Ask a Question