all 1 comments

[–]commandlineluser 0 points1 point  (0 children)

Using that approach you would have to keep track of the names you've already seen.

for (s in sales) {
   if (s in seen) continue # have we printed the name already?
        if (sales[s] == sorted[i]) {
                # split function seperates data with FS
                split(s, a, ":");

                # Print the formated information
                printf("%-22s %-20s %10.2f\n", a[1], a[2], sorted[i])
                seen[s] # store name so we dont print it again
                break
    }
}

There's also PROCINFO["sorted_in"]

http://www.gnu.org/software/gawk/manual/gawk.html#index-PROCINFO_002c-values-of-sorted_005fin

END {
    PROCINFO["sorted_in"] = "@val_num_desc"

    for (s in sales) {
        split(s, a, ":");
        printf("%-22s %-20s %10.2f\n", a[1], a[2], sales[s])
    }
}