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.

4
  • If you'd like to condense a little bit more cut the if from script awk '!($1 in a)||$2=="ca"{a[$1]=$0}... Commented Nov 17, 2014 at 9:58
  • @Costas: Good point, although you've lost some parentheses, so your version doesn't work properly. We need: '!($1 in a)||($2=="ca"){a[$1]=$0};END{for(i in a)print a[i]}' Commented Nov 17, 2014 at 10:06
  • Yes, for portability reason you are right, but in my bash it works without parentheses added by you and without ; before END. But I use GNU version - mawk Commented Nov 17, 2014 at 10:24
  • @Costas: My apologies! I just noticed that when I tried your version I somehow put spaces around the ==. And that only printed `boat as 5/5'. But if get rid of those spaces I do get the proper output. FWIW, I'm using gawk: GNU Awk 3.1.7. But I think I prefer the extra parentheses as it makes the precedence clear. Commented Nov 17, 2014 at 10:38