Trying to move a column into another position within a sed script

Currently the table looks like this

student-id,last,first,hwk1,hwk2,hwk3,exam1,hwk4,hwk5,exam2
pts-avail,,,100,150,100,200,100,150,300
991-78-7872,Thompson,Ken,95,143,79,185,95,135,259
123-45-6789,Richie,Dennis,99,123,89,189,97,139,279
234-56-7891,Aho,Al,78,146,75,176,88,128,285
456-78-9123,Weinberger,Peter,98,149,99,199,99,149,100
345-67-8912,Kernighan,Brian,88,144,88,188,99,111,299
567-89-1234,Joy,Bill,99,150,100,200,23,150,300
678-91-2345,Bourne,Steve,75,98,43,103,17,120,123
444-33-3456,Korn,Dave,100,143,78,123,54,140,234

This is what i am trying to do

student-id,first,last,hwk1,hwk2,hwk3,exam1,hwk4,hwk5,exam2
pts-avail,,,100,150,100,200,100,150,300
991-78-7872,Ken,Thompson,95,143,79,185,95,135,259
123-45-6789,Dennis,Richie,99,123,89,189,97,139,279
234-56-7891,Al,Aho,78,146,75,176,88,128,285
456-78-9123,Peter,Weinberger,98,149,99,199,99,149,100
345-67-8912,Brian,Kernighan,88,144,88,188,99,111,299
567-89-1234,Bill,Joy,99,150,100,200,23,150,300
678-91-2345,Steve,Bourne,75,98,43,103,17,120,123
444-33-3456,Dave,Korn,100,143,78,123,54,140,234

I am trying to do this within one sed shell script and have tried (not all of these are changing the whole table just a few columns just to try and see what works/doesn't)
s/^\([^,]*,\)\([^,]*,\)\([^,]*,\)\([^,]*,\)\([^,]*,\)\([^,]*,\)\([^,]*,\)\([^,]*,\)\([^,]*,\)\([^,]*,\)$/\1\3\2\4\5\6\7\8\9\0/g

s@^\(..\),\(..\),\(..*\),\(...\)@\1,\3,\2,\4@g

s/^\(...\),\(...\),\(...*\)/\1,\3,\2/

s/^\([^,]\),\([^,]\)\([^,]\)\([^...]\)/\1,\3,\2,\4/g

s/^\([^...]\)\([^...]\)\([^.]\),\(...\)/\1,\3\2\4/g

s/^[...],\(...\),\(...\),\(...\)/\2,\1,\3/g

is there a way to do this using the substitute or insert function of sed?

---------- Post updated at 05:17 PM ---------- Previous update was at 05:07 PM ----------

figured it out. thanks to anyone who happened to look at this the answer is

s/^\([^,]*\),\([^,]*\),\([^,]*\),\(.*\)$/\1,\3,\2,\4/
1 Like

Similarly..

 s/\([^,]*\,)\([^,]*\,)\([^,]*\,)/\1\3\2/ inputfile

@michaelrozarl7: keyboard jamming?
Should be

s/\([^,]*,\)\([^,]*,\)\([^,]*,\)/\1\3\2/
1 Like

Yes, my mistake.

sed 's/\([^,]*,\)\([^,]*,\)\([^,]*,\)/\1\3\2/' inputfile