BEGIN { FS = "|" } ! ($2 in students) { students[$2] = $1 scores[$2] = $3 } $2 in students { if ($1 < students[$2]) { students[$2] = $1 scores[$2] = $3 } } END { for (s in scores) print s, scores[s] }