# /* vim: set filetype=awk : */ -*- awk -*- BEGIN { FS=OFS=","; Header = 1; Number = "^[ \t]*[+-]?([0-9]+[.]?[0-9]*|[.][0-9]+)([eE][+-]?[0-9]+)?[ \t]*"; } NR==1 { for(I=1;I<=NF;I++) { Name[I] = $I; Numeric[I] = 1; } } NR> Header { Data[++N]= $0; for(I=1;I<=NF;I++) { Numeric[I] = Numeric[I] && $I ~ Number; if (++Count[I,$I]==1) Word[I,++Word[I,0]]=$I }; } END { print "@relation " (Relation ? Relation : FILENAME) "\n"; for(I=1;I<=NF;I++) print "@attribute " Name[I] " " (Numeric[I] ? "real" : range(I)); print "\n@data\n"; for(I=1;I<=N;I++) print Data[I] } function range(i, j,n,str,sep) { n=Word[i,0]; for(j=1;j<=n;j++) { str = str sep Word[i,j]; sep = ","; }; return "{" str "}"; }