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*

5
  • Thanks, I like the perl solution. It appears to be within a factor of 2 of the speed of grep, which is faster than sed/python/gawk solutions. Is there a simple way to extend it to do the equivalent of egrep "pattern1|pattern2|pattern3"? Commented Jun 13, 2018 at 18:35
  • @dshin, Perl regexes are pretty much an extension of extended regexes like what grep -E uses, so this|that works out of the box. (see this question and Perl's docs for details) Commented Jun 13, 2018 at 18:39
  • @dshin, also, since you're aiming for speed, you could try if replacing the second regex with ... && substr($_, -1, 1) eq "\n"' would be faster. Commented Jun 13, 2018 at 18:42
  • Hm, your original actually is clocking in slightly faster for me, but they are very close. Commented Jun 13, 2018 at 18:44
  • @dshin, allright, just goes to show that Perl's regex processing is pretty well optimized Commented Jun 13, 2018 at 18:49