BEGIN{ Stem="tmp"; IGNORECASE=1; Comments="%.*"; FS=","; } { sub(Comments,"") } /^[ \t]*$/ { next } /@relation/ { Relation=$0 } /@data/ { _data=1 } /@attribute/ { Attr[++A]=$0 } /@relation/,/@data/ { next } _data { Rows++; Cols=NF; for(Col=1;Col<=Cols;Col++) D[Rows,Col]=$Col; next; } { split($0,Words," "); Ranks[Words[3]] = Words[3]; Rank[Words[1]] = Words[3] } END { N=asort(Ranks) for(I=1;I<=N;I++) { delete Use; for(J=I;J<=N;J++) Use[Ranks[J]]; #for(J in Use) print I " wants " J some(Use,Stem "_" I ".arff"); } delete Use; some(Use,Stem "_0.arff"); } function some(want,f, i,use,row,col,sep) { for(i=1;i<=Cols;i++) use[i] = Rank[i] in want; use[Cols] = use[Cols - 1] = 1; print Relation > f; for(i=1;i<=A;i++) if (use[i]) print Attr[i] >> f; print "@data" >> f; for(row=1;row<=Rows;row++) { sep=""; for(col=1;col<=Cols;col++) if (use[col]) { printf sep D[row,col]>>f; sep=","}; print "" >>f; } }