#!/usr/bin/awk # input1: file of a column of scores # input2: column dictionary # out: for each line, votes for the column with highest score # if all scores are null, chooses a random value # the vote is the name of the index given by input2 # default is the first BEGIN{ FS = "\t:"; if (ARGC != 4){ print "error usage: " ARGV[0] " "; exit(1); } column = ARGV[3]; colDictionary = ARGV[2]; class = 1; while ((getline line < colDictionary) > 0){ if (length(line)) classes[class ++] = line; } class --; minclass = classes[1]; maxclass = classes[class]; ARGC -= 2; } { max = 1; for (i = 3; i <= class + 1; i ++){ if ($i > $(max + 1)) max = i - 1; } if ($(max + 1) == 0) decision = classes[int(rand() * class) + 1]; else decision = classes[max]; print column, decision }