How to do a full text search of plaintext files in the DropBox folder

dropboxfindersearchsoftware-recommendationspotlight

I understand that Spotlight will search the full text of files in any folder and will show files that contain instances of the searched text. But I would also like to see highlighted instances of the searched text within the text file. Command-f in a text editor accomplishes this.

The problem is that I have to perform a two-step process which can be very time-consuming when I have a lot of files to search through:

  1. Use Spotlight to locate files that have instances of the searched text in them
  2. Open each file in a text editor individually, command-f, and locate the instance of the text within that file.

Is there any way of combining these two steps into one on OS X? Is there a feature of Spotlight I am missing or an app that will do this? I can do this quite easily on the iPad with the search bar in Daedalus Touch but would love to find out an OS X equivalent.

Thanks for reading.

Best Answer

I often do such search, but I do not use fancy GUIs for that. If you are interested, then read on.

Unix has a great tool called grep which will search for patterns within files. It even supports regular expressions if you use egrep.

Example searching the word "hello" with all case mixture in the Dropbox folder:

cd /Users/name/Dropbox
grep -Riw hello *

That is it. Oh, I forgot to mention you have to use the Terminal application before typing these commands.

If you look for two words "hello" or "bye", you can do:

egrep -Riw "hello|bye" *

If you are looking for every words that contains "ell" (such as hello), you can do:

grep -Ri ell *

And finally (but read the manual page if you want more), matching every file that have the word "iOS" with this particular case:

grep -Rw iOS *