My Spotlight won't shine on me
June 14, 2007 10:12 PM   Subscribe

How can I search for specific strings of text within multiple individual text files in Mac OSX 10.4?

I am trying to search within a very large corpus of text files to look for specific strings of text. One problem is that I don't have all the text files in one folder; there are 150 main folders, and in each of those 150 are on average 25-30 sub-folders, inside which are any number of text files. (note-the data was organized this way when I received it, so it's not my fault!)

I had this idea that Spotlight in Tiger was supposed to make this all very easy, but somehow I can't get it to work. Ideally what I'd like would be for it to look through all the documents in the main folder and return the ones containing the text string, but I'd even settle for going folder-by-folder, as long as I don't have to search each individual file. But I've tried everything, including telling it to search the contents of one specific file that I had already identified as containing the search string, and I still got zero results.

Tell me, oh hive mind, what stupid obvious thing have I somehow forgotten to do?
posted by DiscourseMarker to Computers & Internet (9 answers total)
Did you index the hard drive? That's what preps Spotlight to search properly.
posted by The Deej at 10:14 PM on June 14, 2007

How re-index hard drive.
posted by The Deej at 10:16 PM on June 14, 2007

You can go into the terminal and use the shell if Spotlight doesn't work. Go to your main folder and type:

find . -exec grep "string" {} \;

where "string" is the string you're looking for.
posted by L. Fitzgerald Sjoberg at 10:18 PM on June 14, 2007

I don't know how this works on a Mac, but you can typically do something like this very easily with Google Desktop. I use the PC version nearly every day and it works like a charm.
posted by dhammond at 10:19 PM on June 14, 2007

spotlight would be my first choice. Failing that, you can use old unix tricks. A typical recursive search would look like this (from the command line)

$ cd /whereveryourdocsare
$ find . -type f -print0 | xargs -0 egrep "some string"

Those are zeros up there, not capitol ohs. You can read the man pages for find and xargs to get help but they are on the complex side. Googling for examples might be more help.
posted by chairface at 10:19 PM on June 14, 2007

Aaah...indexing! No, I'm pretty sure I haven't indexed the hard drive, or at least, not lately. I 'll go try that now, thanks!
posted by DiscourseMarker at 10:20 PM on June 14, 2007

Bonus points for the Dead reference, and you can just use the -r option to grep to avoid using find (I'd recommend -s in conjunction).
posted by kcm at 10:27 PM on June 14, 2007

Another problem you might be running into is that spotlight can't do phrase searches. I published a python script to do this at which provides a one-line perl script if all you need is text. There is also easyfind which might do the trick as well.

For making certain all things are in the index, mdimport -p is probably a better way to go about doing this than depending on undocmuented behavior of a preference pane.
posted by KirkJobSluder at 5:55 AM on June 15, 2007

And if everything else fails, you can use BBEdit to search an entire set of folders - and use everything the search box in BBEdit has, such as regular expressions.
posted by DreamerFi at 6:12 AM on June 15, 2007

« Older BabyFilter: I'm looking for advice on how to...   |   Help getting more out of M$ Sendto Powertoys?! Newer »
This thread is closed to new comments.