http://qs1969.pair.com?node_id=445697


in reply to pattern match -vs- *ix grep

Actually, I would expect grep to be faster than Perl all the time. Grep is a special purpose tool, accepting simpler regexes than Perl is able to handle. You can do more with Perl than you can with grep, but, IMO, a match between grep and Perl isn't going the best way to "win people over". Best you can hope for is that Perl isn't much slower.

Having said that, I would just write it as:

perl -ne 'BEGIN {$p = shift} print if /$p/' PATTERN files ...
But that's still significant longer than:
grep PATTERN files ...

Replies are listed 'Best First'.
Re^2: pattern match -vs- *ix grep
by ministry (Scribe) on Apr 07, 2005 at 15:01 UTC
    Very impressive!
    All these one-liners and code snippets do a very good job. When using 'time' to check for speed they all seem to be relatively close as I perfmorm my searching through large files. However (just as everyone has been saying) you just cant beat a general purpose tool like /bin/grep for a simple search - there has been a distinct difference in search times (in particular, as the file searches get larger). I guess now Im going to resort to *dazzling* everyone here at work with my fancy perl regex search strings, multi-file searches,etc... :)
    cheers, ev

    Good judgement comes with experience. Unfortunately, the experience usually comes from bad judgement.