while read foo bar baz waldo fred qux
This is a bash shell script. It may work with other shells.
IFS is an environment variable which holds the field separator.
Set IFS to be the comma character.
The while statement loops over all of the lines of input.
The read function separates the line of input using the IFS (comma) into multiple variables.
The do line is part of the structure of the while statement. Every line between 'do' and 'done' is repeated for each line of input.
The echo command creates output. For each line of input we print out the contents of the variables as filled by 'read', in the desired order, divided by commas.
So these statements work on each line of input, dividing each line up into multiple fields then puts the line back together with the fields in a different order.
One potential problem with this is if there is an embedded comma in a data field, it is not smart enough to figure that out.
If you save this shell script in a file (for example X.sh),
then you would send your CSV file in as standard input (stdin)
and save the reordered CSV output in a new file.
cat mycsv.txt | X.sh > newcsv.txt