grep

Searching Drupal Files with Ack

Ack is a recursive grep-replacement Perl script that you can download from: http://betterthangrep.com It is somewhat similar to "egrep", but is much smarter and has ten times nicer output format. It also automatically ignores annoying .svn files and you can teach it different file types.

If you are a Drupal developer you need to put the following line in your /etc/profile:

export ACK_OPTIONS=--type-set=php=.php,.module,.inc,.install

After which you can enjoy yourself some:

ack --php "check_plain"

Blazing Fast Grep

It was somewhat of an unexpected news and an accidental finding, when I found out today that perl-compatible grep is much faster compared to the default one. I was trying to grep a 145MB text-file

grep -i 'someword' largefile.log - 14 seconds
grep -iP 'someword' largefile.log - under 1 second
grep -iP 'someword.*?' largefile.log - under 1 second

Perl-compatible regexp search is orders of magnitude faster!

It is not surprising that the two modes may be using different algorithms, however... Since perl-compatible is more generic, complex and inclusive of the simpler cases, it makes you wonder why would they bother? Why not just default the simpler case onto the more generic, Perl-compatible one and have both of them fast? I guess - one more glaring example of over-engineering waste; in this case - in a Linux classics :) I, for one, am going to always use the "-P" option from now on.

Syndicate content