I do in file search a lot, and used to love grep. Then I learn the existence of egrep, so I switched to benefit from the advanced regexp. Then I discovered the Eclipse search tool. Much easier to use that grep. Then I found ack : fast, easy, powerful. And now I use grin, which is smooth for pythonistas. I know there is also a couple of this kind of tools with a GUI.

So what tool do you use, and why do you think it's the best. Practical features generally are :

  • fast to fire and use;
  • speedy processing;
  • automatically ignore useless files;
  • colored output;
  • output lines, filename, context;
  • allow complex regexp;
  • allow a custom filtering and ouput;
  • GUI + command line intergation;
  • let you open an editor from the result set.

There are some related posts on SO :

link|improve this question
feedback

migrated from stackoverflow.com Sep 11 '09 at 1:46

This question came from our site for professional and enthusiast programmers.

6 Answers

Personally, I've always gone with ack. Does grin presently have any advantages over ack?

Edit: The major advantage I've seen when trying out out is that grin searches inside compressed files. This is on the TODO list for ack.

link|improve this answer
feedback

Plain old Grep, from 1973. It's been refined and fixed and optimised ever since, so other tools have a lot of catching up to do.

In particular, Ack is very popular, but I don't like it, because with a single line of config, grep does everything it does, is actually faster, and doesn't use false claims in the documentation to self-promote.

I set up my 'grep defaults' using an executable bash script 'grp' which calls grep:

#!/usr/bin/env bash
grep -rI --color --exclude-dir=\.bzr --exclude-dir=\.git --exclude-dir=\.hg --exclude-dir=\.svn --exclude-dir=build --exclude-dir=dist --exclude=tags $*

I did this once in the 1980s, and since then grep does everything that ack does.

You could use an alias instead of a script, but I like to create an executable script like this, then I can invoke it from other programs like vim, so that my search within vim works just like my searches at the command-line. You shouldn't use the GREP_OPTIONS environment variable, because this affects all invocations of grep, even those embedded within other tools, which may break those tools.

Since grep uses blacklists (as specified above) instead of white-lists, it doesn't unexpectedly omit correct results like ack does. I worry that ack must miss occurrences in file-types it doesn't know about. Is this a valid worry, or does it never happen somehow?

I have some Python-specific excludes in my snippet above. No doubt you'll choose some idiosyncrasies of your own as you work. Other options I use in the snippet above are:

  • If you set up a handful of common blacklists to be used as default (e.g. skip '.git' directories and -I to skip binary files) then grep is actually faster, despite ack's loud claims to the contrary.

  • Grep will highlight matches in --color.

  • Grep will recurse into subdirs (-r)

In short, almost every single one of the 'reasons to prefer ack' listed on its homepage are actually undesirable, misleading or downright untrue. Grep does everything ack does, better and faster, plus with decades of bugfixes and optimizations and compatibility and a community of knowledge. The whole Ack project is a massive waste of time that should never have been created.

link|improve this answer
Interesting. I'll have to try this out. Of course, I'll have to use "pcregrep" because I like (read: learned first) PCREs. – Ryan Thompson Feb 26 at 5:47
1  
Ack can show a few lines before and after the matching line. Can any form of grep do that? – darenw Feb 26 at 6:36
1  
@darenw Yes, grep has been doing that since the 1970s. Use options -A (lines after), -B (lines before) or -C (context on both sides.) Like any other options, you can add these to your defaults as described above. – Jonathan Hartley Feb 27 at 14:15
feedback

Findstr works great if you have a Windows machine

link|improve this answer
I only learned about findstr a couple years after writing a hackish version myself for somebody :) – warren Sep 11 '09 at 3:50
feedback

See

link|improve this answer
feedback

On Windows I use the GREP function built into RegexBuddy which lets you build and test your regex within the GUI. The same company also do the much more expensive PowerGREP which I haven't tried.

link|improve this answer
feedback

PowerGREP does all this, and more. Awesome tool (as already mentioned in one of the posts you linked).

link|improve this answer
feedback

Your Answer

 
or
required, but never shown