How to echo columns with consistent spacing?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to echo columns with consistent spacing?
# 1  
Old 08-08-2011
How to echo columns with consistent spacing?

Code:
for (.....)

 echo -e "$Name   | $Age          | $Sex\t|$Grade\t\t"
 
done

output:

Code:
John    |12       |Male           |6th
Jack    |15       |Male           |8th
Zachary    |15       |Male             |9th

I want the lines to line up...but it's out of line when the name is long
# 2  
Old 08-08-2011
Sample input file:
Code:
$ cat file
abc 26 10000
efghij 27 100


Formatted output:
Code:
$ while read a b c
> do
> printf "%-10s %2d %-5d\n" $a $b $c
> done < file
abc        26 10000
efghij     27 100

Guru
# 3  
Old 08-09-2011
Hi.

See https://www.unix.com/unix-dummies-que...#post302473503 for a discussion of tool align ... cheers, drl
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to print out with equal spacing between columns?

For instance, my file contains the following content... set -A array set -A test ${array}=1 ${array}=2 ${array}=3 ${test}="Boy" ${test}="Girl" ${test}="Dog" x=0 while ;do print "${array}" " " "${test}" x=$((x+1) done... (1 Reply)
Discussion started by: TestKing
1 Replies

2. UNIX for Beginners Questions & Answers

Scripts dont give a consistent output..

I have at moment created a setup script that is capable of setting up a workspace for an kaldi enviroment. The script can be found here setup_base_file I guess you wouldn't not be able to run it, without having Kaldi installed, but since this question more relates to scripting, than the... (9 Replies)
Discussion started by: kidi
9 Replies

3. UNIX for Dummies Questions & Answers

Define spacing of columns

Hi! I need to change the spacing assigned to each number in a text file. I have an input file with 5 columns and 3 rows. Here, all numbers are separated by 1 space. I need to change this in such a way that the number in the first column has 6, the number in the second column has 5 and all other... (2 Replies)
Discussion started by: Alauda
2 Replies

4. UNIX for Dummies Questions & Answers

Help with the spacing

while IFS="" read r; do printf "XXX\t%s\n" "$r" done < test1.txt > test.txt The issue is, XXX wud be a dummy column/row added to the file..But i want this XXX column to be a separated as a TAB Delimiter it should be something like XXX 1 XXX 2 (3 Replies)
Discussion started by: saggiboy10
3 Replies

5. Shell Programming and Scripting

Spacing between words

Hi I have a csv file in below format First Line=1 Second Line=2 And the third Line=3 Now comes the fourth Line=4 I want to insert spaces so that the output would be First Line=1 Second Line=2 And the third Line=3 Now comes the fourth Line=4 Can anyone help me do... (10 Replies)
Discussion started by: msivask
10 Replies

6. Solaris

metadevice submirrors 0 and 1 not consistent

At a new job, I've inherited a handful of Solaris 10 SunFire V240 servers. I noticed that the metadevices are not consistent, in a way that I've not seen before.... internal mirrored disks: metadevice d60 has c1t0d0s6 as submirror 0 (d61) and c1t1d0s6 as submirror 1 (d62) metadevice... (1 Reply)
Discussion started by: Max Power
1 Replies

7. Shell Programming and Scripting

Trouble getting consistent PID of tomcat server from ps

Hello all, I am working on a script to automate the process of restarting some tomcat servers. The versions of tomcat are pretty old and it often happens that they don't shut down gracefully and the PID needs to be manually killed. I am having a bear of a time getting a consistent PID from ps... (1 Reply)
Discussion started by: dkaplowitz
1 Replies

8. UNIX for Advanced & Expert Users

keep UIDs/GIDs consistent

Hi, What is the best ways to keep UIDs and GIDs consistent across unix and linux server. my company have a servers running on hpux, linux, aix and many of them have veritas cluster and hacmp running, many time user account have been created only on one of the cluster node and not the others... (4 Replies)
Discussion started by: robertngo
4 Replies

9. UNIX for Dummies Questions & Answers

echo into columns

hello there, Thank you for any help you may offer. I have the fallowing command echo `ls -1 /Volumes/ximage2/$line/images/ | wc -l` $line which give me the number of sub directories followed by the name of the parent directory of interest to me. it ends up looking like this 1... (2 Replies)
Discussion started by: Movomito
2 Replies
Login or Register to Ask a Question