Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Help Justify with printf in ksh script

Status
Not open for further replies.

ryanc2

MIS
Apr 18, 2003
73
0
0
US
I've got a KSH script that uses awk to print $5 and $6 to the screen. $5 can be 1 or 2 digit number, and $6 can be up to 7 digits.

I'd like to justify spacing between the two columns to appear below:

1 1234456
2 12359609
20 5309286

Currently, I have hardcoded spaces with echo " ", but if $5 is 2 digits, it obviously adds an extra space before $6.

Any help would be appreciated.

Thanks in advance...
 
You may consider either:
print $1"\t"$2
Or:
printf "%2d %7d\n",$1,$2

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top