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; } END { print Relation > OutputFile; for(I=1;I<=Cols-2;I++) { target="-"I"-"; if (index(SelectedAttributes,target)!=0) print Attr[I] >> OutputFile; } print Attr[Cols-1] >> OutputFile; print Attr[Cols] >> OutputFile; print "@data" >> OutputFile; for(row=1;row<=Rows;row++) { sep=""; for(I=1;I<=Cols-2;I++) { target="-"I"-"; if (index(SelectedAttributes,target)!=0) { printf sep D[row,I] >> OutputFile; sep=","; } } #in case these are the only two selected, the seperator is set to "," in the middle printf sep D[row,Cols-1] >> OutputFile; sep="," printf sep D[row,Cols] >> OutputFile; print "" >> OutputFile; } }