Change many columns position/order

Hi everyone,

Please some help over here. (I�m using cygwing)

I have files with 40 columns and 2000 lines in average. I�m trying to change the order position as follow.

Original columns position:

1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40

Desired columns position:

1,10,21,5,9,7,32,18,20,37,15,2,3,4,6,8,11,12,13,14,16,17,19,22,23,24,25,26,27,28,29,30,31,33,34,35,36,38,39,40

I was trying using the follow awk script:

awk -F"," '{print $1,$10,$21,$5,$9,$7,$32,$18,$20,$37,$15,$2,$3,$4,$6,$8,$11,$12,$13,$14,$16,$17,$19,$22,$23,$24,$25,$26,$27,$28,$29,$30,$31,$33,$34,$35,$36,$38,$39,$40'}' infile

but doesn�t work only if I reduce the script to the first 11 columns, as follow:

awk -F"," '{print $1,$10,$21,$5,$9,$7,$32,$18,$20,$37,$15}' infile

Somebody knows what is wrong with my script?

How can be a best way to change all 40 columns position?

Thanks in advance for any help.

Regards.

Hi.

You have an extraneous single quote at:

$40'}' infile

I removed the one just before the closing curly brace and it worked for me.

Note that if you need the comma to be a separator in the output, you will need to change the value of variable OFS ... cheers, drl

It works on my Solaris box with all kinds of awk's. Is the extra ' at the end of your awk statement a typo or the cause of your problem: ... $40'}' ...

Hey, many thanks guys!. Yes, a clear typo:D. I didn�t see the extra '.

Thanks, thanks, thanks.

Best regards.