#!/usr/bin/gawk -f constants.awk -f BEGIN { FS=OFS=","; Header =2; } 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 "}"; } #Print a string in key-sort order. function saya(s,a,q1,q2,eol, i,j,n,tmp,str,sep) { q1= q1 ? "\"" : ""; q2= q2 ? "\"" : ""; for(i in a) { sep=""; str= s"["; n=split(i,tmp,SUBSEP); for(j=1;j<=n;j++) { str=str sep q1 tmp[j] q1; sep=","; } print str "] = " q2 a[i] q2 eol | "sort"; }; close("sort") }