How to pad spaces


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to pad spaces
# 1  
Old 09-26-2002
Question 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
# 2  
Old 09-26-2002
In ksh you can use the typeset command:
typeset -L30 fieldA
typeset -R15 fieldB
echo "${fieldA}${fieldB}"
# 3  
Old 09-26-2002
you can also use perls format or even printf.
# 4  
Old 09-30-2002
Lightbulb

Simple and beautiful.

Many thanks Smilie
Login or Register to Ask a Question

Previous Thread | Next Thread

7 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Pad 0 to the right

I need to pad 0 to a number on the right. to make it 9 digit in total. My number is 2457 output should be 245700000 Please do wrap your samples/codes into CODE TAGS as per forum rules. (3 Replies)
Discussion started by: varun22486
3 Replies

2. Shell Programming and Scripting

Left pad spaces using awk or sed

Hi,I've a unix pipe delimited file as below f1|f2|f3|f4|f5|f6 My requirement is to pad spaces on the left to fields f2, f3 and f5. Field Lengths according to file layout f2 - 4 char f3 - 5 char f5 - 3 char If my record is as below 1|43|bc|h0|34|a Output record should be as below 1| 43| bc|h0|... (4 Replies)
Discussion started by: Soujanya_K
4 Replies

3. UNIX for Dummies Questions & Answers

pad

Hi All I need a pad a . to befoure a last digi ex 1258 --> 125.8 help to do thanks (4 Replies)
Discussion started by: nalakaatslt
4 Replies

4. UNIX for Dummies Questions & Answers

pad Zeros

Hi can I know command to pad Zeros to a value I get 16 and I need to send 0000000016 (5 Replies)
Discussion started by: mgirinath
5 Replies

5. Solaris

number pad in vi

Hi, I'm on a sunos SVR4.0 box, my number pad works on the command line but does not work in vi any ideas how to enable it under vi? Thanks (5 Replies)
Discussion started by: c19h28O2
5 Replies

6. UNIX for Dummies Questions & Answers

touch pad not working

i just recenlty bought this hp pavillion laptop and installed linux on it.. i found that the touchpad doesn't work.. so i thought that hp pavillion doesn't have touchpad// silly me! // more recently I reinstalled fedora core 2.6.8-1-521 i686 and also xp professional... xp i found has touch pad and... (5 Replies)
Discussion started by: moxxx68
5 Replies

7. UNIX for Dummies Questions & Answers

number pad?

Is there anyway to use the fr*$%& number pad in VI? Anyway? Anyway at all? All it does now random movements and inserts of characters (2 Replies)
Discussion started by: nelsonenzo
2 Replies
Login or Register to Ask a Question