How to replace commas with white spaces in a csv, but inserting a different number of space after each column

awkcommand linecsvsedtext processing

I have a file in the following format:

s1,23,789  
s2,25,689

and I would like to transform it into a file in the following format:

s1      23  789  
s2      25  689

i.e 6 white spaces between the 1st and 2nd column and only 3 white spaces between the 2nd and 3rd column?

Is there a quick way of pulling this off using sed or awk?

Best Answer

Something along these lines should do it:

awk 'BEGIN{IFS=","} {printf("%s      %s   %s\n", $1, $2, $3)}' input_file

And equivalently and more terse (from the comments):

awk -F ',' '{printf("%s      %s   %s\n", $1, $2, $3)}' input_file
Related Question