# /* vim: set filetype=awk : */ -*- awk -*- BEGIN { Trainf = "train.arff"; Testf = "test.arff"; Seed = 1; Bins = 3; Bin = 1; } { sub(/%.*/,"") } /^[ \t]*$/ { next } /@relation/ { srand(Seed ? Seed : 1); printf "">Trainf; printf "">Testf } /@relation/,/@data/ { print $0 >> Trainf; print $0 >> Testf; next } { Line[rand()] = $0; Lines++ } END { Start = Lines/Bins * (Bin - 1) ; Stop = Lines/Bins * Bin; for(I in Line) { N++; What = (N>= Start && N < Stop) ? Testf : Trainf print Line[I]>>What; } }