reformatting a file with columns using AWK
by atjurhs from LinuxQuestions.org on (#6M744)
hi guys,
i wrote an AWK script that prints out data using this command
Code:printf("\n%s,%s,%.5f,%.5f,%s",aray1,aray2,aray3,aray4,aray5)it gives me output that looks like
Code:fieldname1,val11,fieldname2,val21,fieldname3,val31,fieldname4,val41,fieldname5,val51
fieldname1,val12,fieldname2,val22,fieldname3,val32,fieldname4,val42,fieldname5,val52
fieldname1,val13,fieldname2,val23,fieldname3,val33,fieldname4,val43,fieldname5,val53
fieldname1,val14,fieldname2,val24,fieldname3,val34,fieldname4,val44,fieldname5,val54
fieldname1,val15,fieldname2,val25,fieldname3,val35,fieldname4,val45,fieldname5,val55
fieldname1,val16,fieldname2,val26,fieldname3,val36,fieldname4,val46,fieldname5,val56i need my output to look like
Code:fieldname1,fieldname2,fieldname3,fieldname4,fieldname5
val11,val21,val31,val41,val51
val12,val22,val32,val42,val52
val13,val23,val33,val43,val53
val14,val24,val34,val44,val54
etc.i don't know how to "transpose" the data. maybe it would be better to use a different kind of print statement in my AWK script? or maybe easier to write a another AWK script to do it, idk?
guidance would be much appreciated, thank you
i wrote an AWK script that prints out data using this command
Code:printf("\n%s,%s,%.5f,%.5f,%s",aray1,aray2,aray3,aray4,aray5)it gives me output that looks like
Code:fieldname1,val11,fieldname2,val21,fieldname3,val31,fieldname4,val41,fieldname5,val51
fieldname1,val12,fieldname2,val22,fieldname3,val32,fieldname4,val42,fieldname5,val52
fieldname1,val13,fieldname2,val23,fieldname3,val33,fieldname4,val43,fieldname5,val53
fieldname1,val14,fieldname2,val24,fieldname3,val34,fieldname4,val44,fieldname5,val54
fieldname1,val15,fieldname2,val25,fieldname3,val35,fieldname4,val45,fieldname5,val55
fieldname1,val16,fieldname2,val26,fieldname3,val36,fieldname4,val46,fieldname5,val56i need my output to look like
Code:fieldname1,fieldname2,fieldname3,fieldname4,fieldname5
val11,val21,val31,val41,val51
val12,val22,val32,val42,val52
val13,val23,val33,val43,val53
val14,val24,val34,val44,val54
etc.i don't know how to "transpose" the data. maybe it would be better to use a different kind of print statement in my AWK script? or maybe easier to write a another AWK script to do it, idk?
guidance would be much appreciated, thank you