Beyond grep: ack, a code search tool for programmers
beyondgrep.com
beyondgrep.com
You can limit the files it searches with -G <pattern>
in these cases ag is noticeably faster (orders of magnitude, in some cases), especially if you're just searching a literal and not with a regex pattern.
the author has done some really cool performance hacks, and written some great blog posts[1] along the way.
[1]: http://geoff.greer.fm/2012/09/03/profiling-ag-writing-my-own...
time rgrep aes . > /dev/null
real 0m0.900s
user 0m0.548s
sys 0m0.340s
# Somewhat similar output to ag:
time rgrep -n --color aes . > /dev/null
real 0m1.177s
user 0m0.876s
sys 0m0.288s
time ag aes > /dev/null
real 0m1.147s
user 0m1.040s
sys 0m0.548s
# Using fixed strings in grep, limiting us to searching c-files
time rgrep -n --color -F --include='*.c' aes . > /dev/null
real 0m0.936s
user 0m0.720s
sys 0m0.208s
time ag -G \.c aes > /dev/null
real 0m1.130s
user 0m1.140s
sys 0m0.428s
This is on an encrypted volume sitting on top of a low end SSD, all runs
with hot chache. The times here are from ag in Debian -- I tried a build
from upstream git -- but with essentially the same time.I guess ag might make sense under OS X -- but there doesn't appear to be any (speed) advantages under GNU/Linux.
I was actually contrasting it to ack in my speed claims. I don't expect that it'd be that much faster than GNU grep in most situations.
This lets me completely tailor the file I search using find's filters (e.g., only search files with a .py extension, and skip .svn/ directory). E.g. assuming I'm in my project's root directory:
find . -name .svn -prune -o -name '*.py' -print | xargs grep -Hi 'string or RE I am looking for' ack --python PATTERN [DIRECTORY]ag -i -G '\.py$' 'string or RE I am looking for'
I grant that these other tools are great, but I like using the standard utilities because, among other things, once you learn 'find' and 'xargs' you can piece together all kinds of other commands and you don't have to remember a tool-specific syntax (at least for the 'find' and 'xargs' parts).
grep bar -A 5 -B 5 files... | grep foo
-A n prints n lines following the match (bar) and -B n prints n lines before the match.(A - after, B - before, C - context)
Bundle 'mileszs/ack.vim'