Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

3
  • 1
    @EdMorton absolutely right about the sort, thanks.Should be fixed now. As for tabs, though, what if the 2nd field had a tab? And sure, !++seen[$2]++ might be more idiomatic, but it's also more cryptic to those not familiar with the idiom, so I don't see any benefit in using it here. I've done so often enough in other cases. Commented Apr 4, 2020 at 15:44
  • Good point about the possibility of the 2nd field containing a tab, I hadn't considered that. wrt the idiom - IMHO idioms are good for everyone to become familiar with if they're going to be using a tool/language so if we use one and someone isn't familiar with it and investigates or asks then it's still a win. Commented Apr 4, 2020 at 15:50
  • I deleted my answer and upvoted yours since they're now both so similar. Talking of cryptic though {if(!a[$1]||length($0)>length(a[$1])){a[$1]=$0}}END{for(i in a){print a[i]}} could stand a few newlines and indenting and maybe a temp var or 2 :-). Commented Apr 4, 2020 at 15:54