awk script help

Hi

I have a comma delimited file with 2 columns, however I need to manipulate it, in such a way that the first column is horizontal and the second column is underneath it.

text1,123
text2, 345
text3, 678
text4,987
text1,text2,text3,text4
123,345,678,987

if you searched for transpose you'd have found a couple of leads...
awk -F, -f bomb.awk OFS=, myFile where bomb.awk is:

{for(i=1;i<=NF;i++){a[i,NR]=$i};m=NF;n=NR}
END {
   for(j=1;j<=m;j++)
         for(k=1;k<=n;k++)
           printf("%s%s",a[j,k], (k==n) ? ORS : OFS)
}
1 Like