justifying the fields

hi experts,
i just need a help that my script is generating the output which i will mentioned below but the fileds are not justified the alignment is disturbed.

0 8718 8718 0 8777
1 7450 7450 0 7483
2 5063 5063 0 5091
3 3840 3840 0 3855
4 3129 3129 0 3142
5 2400 2400 0 2419
6 2597 2597 0 2604
7 3055 3055 0 3078
8 4249 4249 0 4266
9 4927 4927 0 4957
10 8920 8920 0 8978
11 19567 19567 0 19675
12 15249 15249 0 15330
13 13930 13930 0 14015
14 13694 13694 0 13742
15 13066 13066 0 13122
16 12477 12477 0 12548
17 12791 12791 0 12855
18 13754 13754 0 13842
19 13181 13181 0 13259
20 12991 12991 0 13048
21 12435 12435 0 12484
22 13545 13545 0 13624
23 14584 14584 0 14656
total 235612 235612 0 236850

so at the end i just want the output in the correct format and justified like.
0 8718 8718 0 8777
1 7450 7450 0 7483
2 5063 5063 0 5091
3 3840 3840 0 3855
4 3129 3129 0 3142
5 2400 2400 0 2419
6 2597 2597 0 2604
7 3055 3055 0 3078
8 4249 4249 0 4266
9 4927 4927 0 4957
10 8920 8920 0 8978
11 19567 19567 0 19675
12 15249 15249 0 15330
13 13930 13930 0 14015
14 13694 13694 0 13742
15 13066 13066 0 13122
16 12477 12477 0 12548
17 12791 12791 0 12855
18 13754 13754 0 13842
19 13181 13181 0 13259
20 12991 12991 0 13048
21 12435 12435 0 12484
22 13545 13545 0 13624
23 14584 14584 0 14656
total 235612 235612 0 236850

so please kindly tell me that how i can justfied te filelds properly though shell script.

i dont see the justications in ur message..
does this help?

awk '{printf ("%8s%8s%8s%8s%8s\n",$1,$2,$3,$4,$5);}' sample

Hi.

If you are interested in a general solution, S Kinzler has shared a very good perl script, align:

# align - filter to align columns of text
# Steve Kinzler, kinzler@cs.indiana.edu, Jun 00/Oct 01/Dec 01
# see website http://www.cs.indiana.edu/~kinzler/align/
# http://www.cs.indiana.edu/~kinzler/home.html#unix

Using it on your data, here is a sample of the output:

     1  0       8718   8718      0   8777
     2  1       7450   7450      0   7483
     3  2       5063   5063      0   5091
     4  3       3840   3840      0   3855
     5  4       3129   3129      0   3142
   ...
    21  20     12991  12991      0  13048
    22  21     12435  12435      0  12484
    23  22     13545  13545      0  13624
    24  23     14584  14584      0  14656
    25  total 235612 235612      0 236850

Best wishes ... cheers, drl