append blank spaces at the end of a variable string

Hello, could you please help with this one. I have an input file like this:

123,4567,89000
123456789,9876543,12

and for the output I need strings to be with the fixed length, let's say 15, and if the string is -lt 15 to be populated with blanks at the end until it reach 15, like this:

123 ,4567 ,89000 
123456789 ,9876543 ,12

I tried this, but it is not working....

while [ $len -lt 15 ]; do $1=`echo " "$1`; done

Thanks!

Try this

awk -F',' '{OFS=","}{ for (i=1;i<NF;i++) {printf("%-15s,",$i)}{printf($NF"\n")}}' file1
1 Like