The grep -ri command (recursively search for matches, ignoring case) in Terminal is incredibly useful, but incredibly slow. In OS X, we can leverage mdfind to quickly find the files containing our search string, then use grep to find the strings within only those files. Here's a script to do just that.
#!/bin/bash # # Spotlight metadata find and grep by Daniel.Hoherd at gmail dot com ## Check for at least two arguments, print usage if else if [ $# -lt 1 ] ; then echo "usage: $0 searchstring [dir or file] [dir2 or file2]" exit ; fi ss=$1; shift; files=$@; until [ -z "$1" ] ; do thisitem=$1 onlyin="-onlyin '$thisitem' $onlyin" shift done; eval mdfind -0 $onlyin "$ss" | xargs -0 grep -Hi "$ss"
Mac OS X Hints
http://hints.macworld.com/article.php?story=20100320112701285