I have a tab delimited Excel file with 65 columns and 350 rows. I need to rearrange it such that columns 60-65 are inserted after column1 , followed by col2, col3 ... col 59 using only PERL .. i.e.
Col1 Col60 Col61 Col62 Col2 Col3 Col4 Col5 Col6
I wrote a shell command to do it :
paste <(awk -F '\t' '{print $1}' part.xls ) <(awk -F '\t' '{print $60}' part.xls ) <(awk -F '\t' '{print $61}' part.xls ) <(awk -F '\t' '{print $62}' part.xls ) <(awk -F '\t' -v f=2 -v t=59 '{ for (i=f; i<=t;i++) printf("%s\t%s", $i,(i==t) ? "\n" : OFS) }' part.xls) > new.xls
part.xls = original file with 65 columns new.xls = file with reordered columns
I need to incorporate this into my PERL script . I tried using system command but it gave me errors.
system("paste <(awk -F '\t' '{print \$1}' part.xls ) <(awk -F '\t' '{print \$60}' part.xls ) <(awk -F '\t' '{print \$61}' part.xls ) <(awk -F '\t' '{print \$62}' part.xls ) <(awk -F '\t' -v f=2 -v t=59 '{ for (i=f; i<=t;i++) printf("%s\t%s", $i,(i==t) ? "\n" : OFS) }' part.xls) > new.xls");
Can someone plz point out my mistake ? Thanks in advance.