1748169 Members
4321 Online
108758 Solutions
New Discussion юеВ

Re: Script question

 
SOLVED
Go to solution
Alex Lavrov.
Honored Contributor

Script question

Hello,
I want to know what are the standart ways to format the output of the script?

For explamle I need the following output:

Mount Size Comments
/opt 345 Testing bla
/software/omni 8003 bla bla bla

If I use printf(1) to format the output, it's only padding from the left and I need padding from the right, is there any way to tell printf to pad from the right?

(I'm using onl bash, no perl, php etc ...)
I don't give a damn for a man that can only spell a word one way. (M. Twain)
5 REPLIES 5
RAC_1
Honored Contributor

Re: Script question

man adjust
adjust -r, else awk printf
There is no substitute to HARDWORK
Stephen Keane
Honored Contributor
Solution

Re: Script question

Not sure what layout you want, as the HP ITRC code strips away multiple spaces in your post.

But the format argument of bash's printf allows for a '-' sign to indicate right alignment and a figure to indicate field width.

Example

bash$ printf "%14d\n" 12
............12

AND

bash$ printf "%-14d" 12
12............

I've replaced the spaces with '.'s to show you what is happening.
A. Clay Stephenson
Acclaimed Contributor

Re: Script question

printf will pad in either direction. Some combination of the following example will work for you:

printf "%20s%-20s%-20.20s\n" AA BB CC

The "-" pads on the right, -20.20 pads on the right but also limits the total width of the field to 20 so that it can both pad and truncate.
If it ain't broke, I can fix that.
Gordon  Morrison_1
Regular Advisor

Re: Script question

I don't know about bash, but ksh has the following features:

typeset -L var1 # var1 is Left-justified, remove leading spaces
typeset -R var2 # var2 is Right-justified, remove trailing spaces
typeset -L8 var3 # var3 is Left-justified, padded to 8 chars total, remove leading spaces
typeset -R9 var4 # var4 is Right-justified, padded to 9 chars total, remove trailing spaces
What does this button do?
Alex Lavrov.
Honored Contributor

Re: Script question

thanx for the help!
I don't give a damn for a man that can only spell a word one way. (M. Twain)