Persoanlly, I would approach this by a bash script.
This is some outline pseudo code
while read -a aline
for=1 to sizeof aline; do
if (i modulo Y not equal to zero) AND (i less than sizeof aline)
echo -n aline[i-1]","
elif (i equals sizeof aline)
done << inputfile