How to pad spaces

Hello,
I have to write a function to input a Label and a number, and output a line as the following format:

Column 1 to 30: field label, left justified.
Column 31 to 45: A number, right justified.

The middle is padded with space. May I know how can I achieve this? (I don't know how to count the length of the label/number, and how to pad the spaces in between.)

Please help.

Many thanks.

Sarah

In ksh you can use the typeset command:
typeset -L30 fieldA
typeset -R15 fieldB
echo "${fieldA}${fieldB}"

you can also use perls format or even printf.

Simple and beautiful.

Many thanks :slight_smile: