grep (BSD grep) 2.5.1-FreeBSD on mac os 10.8 line regexp mode not working with overlapping patterns

后端 未结 1 652
终归单人心
终归单人心 2021-01-12 09:15

It seems like the stock version of grep (version info: grep (BSD grep) 2.5.1-FreeBSD) under mac os 10.8 has an issue with patterns sharing a common prefix when being run in

相关标签:
1条回答
  • 2021-01-12 09:36

    Verified; this does look like a bug in Apple and/or FreeBSD grep. (This is completely unsurprising to me; FreeBSD grep is a standards-hating pile of poo. My employer installs GNU grep on all our Mac systems rather than put up with FreeBSD's wacky behavior. And yes, GNU grep finds both lines in your example.)

    If portability between Mac and Linux is an objective, I strongly recommend abandoning grep altogether and just using perl (or something like ack, which depends on perl).

    @akostadinov's suggestion to put longer patterns before shorter ones in f2.txt does seem to work around the bug, but I would be leery of relying on something like that. It works on this toy example, but does it work in general, and how expensive will it be when you find out?

    0 讨论(0)
提交回复
热议问题