Search for text in multiple Word files via the Terminal
Feb 23, '05 07:01:00AM
Contributed by: Safar
Have you ever wanted to search for a string of text across multiple Word files? Paste this in the Terminal:
$ find . -name '*.doc' -exec grep -li 'danny the dog' {} \;
It will print the names of the files containg the string danny the dog, along with the directory in which they were found. Case is not sensitive thanks to -i option on grep.
[robg adds: The find . command will search down from the currently active directory. So if you open a new Terminal window and just enter the above command, it will search your user's entire Home directory structure. If your word files are elsewhere, you'll need to do a cd /path/to/Word/files first, then run the command. Tiger will apparently make this trick unnecessary, but until it's released, it's a handy shortcut (and if you do want case sensitivity, just leave off the i on the -li options string.]
Comments (11)
Mac OS X Hints
http://hints.macworld.com/article.php?story=20050217130820258