BEGIN { FS = ","; #file = "simlog.csv"; min=1000000000000; simNum=0; getline; } { policies[simNum] = $1 " = " $2; canMin = round($6*10000)/10000; policyMinE[simNum] = canMin; policyMedE[simNum] = $6; policySpE[simNum] = $7; policyMedEff[simNum] = $10; policySpEff[simNum] = $11; policyMedDef[simNum] = $14; policySpDef[simNum] = $15; policyMedTh[simNum] = $18; policySpTh[simNum] = $19; policyMedMon[simNum] = $20; policySpMon[simNum] = $21; if (canMin < min) min = canMin; simNum++; } END { numPol = 0; #print "min is " min; #output = "min is " min "\n"; print "\nNumber of total policies is " simNum "\n"; output = "Number of total policies is " simNum "\n\n"; for (i=simNum-1; i>=0; i--) { print policies[i]; output = output policies[i] "\n"; numPol++; if (policyMinE[i] <= min) { print "\nNumber of recommended policies is " numPol; output = output "\nNumber of recommended policies is " numPol "\n"; print "Results of applying above policies:"; output = output "\nResults of applying above policies:"; print "\tEnergy:\n\t\tmedian: " policyMedE[i] "\n\t\tspread: " policySpE[i]; output = output "\n\tEnergy:\n\t\tmedian: " policyMedE[i] "\n\t\tspread: " policySpE[i]; print "\tEffort:\n\t\tmedian: " policyMedEff[i] "\n\t\tspread: " policySpEff[i]; output = output "\n\tEffort:\n\t\tmedian: " policyMedEff[i] "\n\t\tspread: " policySpEff[i]; print "\tDefects:\n\t\tmedian: " policyMedDef[i] "\n\t\tspread: " policySpDef[i]; output = output "\n\tDefects:\n\t\tmedian: " policyMedDef[i] "\n\t\tspread: " policySpDef[i]; print "\tThreat:\n\t\tmedian: " policyMedTh[i] "\n\t\tspread: " policySpTh[i]; output = output "\n\tThreat:\n\t\tmedian: " policyMedTh[i] "\n\t\tspread: " policySpTh[i]; print "\tMonths:\n\t\tmedian: " policyMedMon[i] "\n\t\tspread: " policySpMon[i]; output = output "\n\tMonths:\n\t\tmedian: " policyMedMon[i] "\n\t\tspread: " policySpMon[i]; break; } } print output > "policy.txt"; } function round(x, ival, aval, fraction) { ival = int(x) if (ival == x) return x fraction = x - ival if (fraction >= .5) return ival + 1 else return ival }