Format data to columns addind spaces

Hi all,

I have a problem to format data from different database queries into one look. The input data are as follows, every line has the same number of values but a different number of characters:

adata, bdata,     cdata,    ddata
fffdata,  gdata,      hdata,    idata
jdata,    kdata,   ldata,   mdaata

What I want is a formatted output with the same number of characters in each line:

adata,   bdata, cdata, ddata
fffdata, gdata, hdata, idata
jdata,   kdata, ldata, mdaata

I�m useing Redhat-Linux and ksh.

Thanks for your support!

What is the difference in your input and output ? Both looks same. Please put your input and output in tags.

Hi dj,

thanks for your remark. I added the tags. As you probably see now the data of the lines start in the same column.

Ok so you need formating of the output... there are varios ways
1.

echo "$VAR1  ,    $VAR2   ,    $VAR 3"
awk  { printf("%s,    %s,    %s",$1,$2,$3 ) } 
  1. Using Perl FORMAT .. see this
    Perl format Primer (1/2)

echo -e "$VAR1,\t$VAR2,\t$VAR 3"

Try:
Assuming the width is 10 characters.

awk '{ printf "%-10s%-10s%-10s%-10s\n",$1,$2,$3,$4 }'  filename

bash

#!/bin/bash
while IFS="," read -r a b c d
do    
    printf "%-10s%-10s%-10s%-10s\n" $a,$b,$c,$d   
done <"file"

@ all,

thanks a lot for your support, I checked the last post with the loop, it works perfect!