Artificial intelligent assistant

How to split a single line of fields delimited by commas into multiple lines with a specific number of fields in each line? I have a file like so Hello,Hi,Hullo,Hammers,Based,Random For `n=2`, output must be like so Hello,Hi Hullo,Hammers Based,Random For `n=3`, output must be like so Hello,Hi,Hullo Hammers,Based,Random How could I accomplish this using awk/sed? Edit: `n` is a factor of number of fields

$ awk -v n=2 -F',' '{for (i=1;i<=NF;i++) printf "%s%s", $i, (i%n ? FS : ORS)}' file
Hello,Hi
Hullo,Hammers
Based,Random

$ awk -v n=3 -F',' '{for (i=1;i<=NF;i++) printf "%s%s", $i, (i%n ? FS : ORS)}' file
Hello,Hi,Hullo
Hammers,Based,Random


In your question you didn't address how to handle cases where the number of fields don't divide evenly by `n` so I haven't addressed it here either.

xcX3v84RxoQ-4GxG32940ukFUIEgYdPy 94eb16b83b0f614d7cfd42a97734a89e