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.

6
  • 2
    Is there any benefit in this over the top answers? All of them are significantly shorter than this, so I don't quite see the benefit here. Commented Feb 28, 2024 at 12:50
  • @terdon Yes, it's much more efficient than the top 2 answers, and shorter than the third answer. This answer was provided in a helpful comment by AdminBee, and I simply converted it into a real answer so others can benefit from it as I did (comments are often deleted). Commented Feb 28, 2024 at 22:23
  • 1
    How is it more efficient? Easier to read is subjective, I find this far more obscure since the behavior of awk to automatically increment something without explicitly being told to (with just a[$0]) is kind of esoteric. However, if you find it easier, that's absolutely fine. I just don't see how this would be more efficient than awk '!NF || !seen[$0]++'. I tested on a file with ~100k lines and couldn't see any significant difference in speed between that and yours. And both keep the same amount of data in memory, so it isn't "much more efficient" Commented Feb 29, 2024 at 11:56
  • @terdon Did you read the answer for which AdminBee's comment was posted, and the explanation provided in that answer by cuonglm? Why are you not questioning that post too? Please ask for clarification in the comment section of that answer: unix.stackexchange.com/a/131261/141350 Commented Feb 29, 2024 at 12:02
  • 1
    I am questioning, as you say, because this is a new answer which, as far as I can tell, isn't providing any benefit over any of the existing answers. Cuonglm's was posted ten years ago and at the time of posting was providing a new approach. As you can see, I haven't downvoted, I was just wondering why this was posted since it didn't seem to be adding anything new, so I asked in case I was missing the benefit. You claimed better readability (fair enough, I don't see it, but this is subjective) and then that this is "much more efficient" and that doesn't seem to be true. That's all. Commented Feb 29, 2024 at 12:40