BEGIN { FS = " " OFS = " " } /^@relation/ { Relation = $2 } /^@attribute/ { addCol($2) } /^@class/ { addClass($2) } /^@data/ { readData() } function addCol(col) { Cols[++Cols[0]] = col } function addClass(col) { Cols[++Cols[0]] = col Classes[Cols[0]] = 1 } function adjustCols( tmp,k) { #desharnais-specific column adjustments # tmp = Cols[6] # Cols[6] = Cols[12] # Cols[12] = tmp # for (k=1; k <= Cols[0]; k++) # print k "::"Cols[k] } function readData( i) { FS = " " while (getline) { Data[0]++ for (i=1; i <= Cols[0]; i++) { Data[Cols[i],Data[0]] = $i } } } END { writeHeader() writeData() } function writeHeader( c,r,sorted) { print "@relation "Relation print "" for (c=1; c<=Cols[0]; c++) { if (c in Classes) printf "@class "Cols[c] else printf "@attribute "Cols[c] cntr=0 for (r=1; r<=Data[0]; r++) { if(isunique(Data[Cols[c],r],sorted,cntr+1)) sorted[++cntr] = Data[Cols[c],r] } asort(sorted) for (r=1; r<=cntr; r++) printf " "sorted[r] printf "\n" split("",sorted,"") } print "\n@data" } function isunique(val, arr, cntr, i,result) { # printf "is "val" in sorted:" result = 1 for (i=1; i