# /* vim: set filetype=awk : */ -*- awk -*- BEGIN { OFMT = "%.2f"; Got = 1 Want = 2; Prefix = ""; True = "true"; ## define symbol 1 False = "false"; ## define symbol 2 A=B=C=D=0 ; FS=OFS="," } function yes(s) {return s ~ True} function no(s) {return s ~ False} { sub(/#.*/,"") } /^[ \t]*$/ { next } NF==2 { N++; Predicted=$Want; Actual=$Got; if (Predicted == Actual) Good++; if (no( Actual) && no( Predicted)) A++; if (yes(Actual) && no( Predicted)) B++; if (no( Actual) && yes(Predicted)) C++; if (yes(Actual) && yes(Predicted)) D++; } END { Precision=Accuracy=Pf=Pd=0; if (C+D > 0 ) Precision = 100*D/(C+D); if (N > 0 ) Accuracy = 100*Good/N; if (A+C > 0 ) Pf = 100*C/(A+C); if (B+D > 0 ) Pd = 100*D/(B+D); if(Prefix) printf Txt=Prefix OFS; print sprintf(OFMT,Accuracy), sprintf(OFMT,Pd), sprintf(OFMT,Pf), sprintf(OFMT,Precision); }