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*

4
  • + good idea! I expanded your table, in a new answer, feel free to edit (the final picture is not so clear, but I believe @maxschlepzig is steel the faster solution) Commented Mar 4, 2015 at 8:35
  • 1
    maxschlepzig's solution is super fast! Commented Apr 1, 2016 at 6:36
  • For your Perl answer, if you're printing the final $x in an END block, then won't you only get a single-number return? But the OP asked for a count per line ... ? Commented Oct 17, 2023 at 18:25
  • 1
    @jubilatious1 I explained in the text that my test example only had a single line, which was my use case. I came to this page (almost 10 years ago :) ) originally trying to find a way that wouldn't break with the number of matches I was dealing with. So you are correct, it does not fit the original question if a file contains more than one line. Commented Oct 18, 2023 at 19:21