Saturday, March 30, 2013

Search multiple files for a specific word

grep 'Word or phrase I am looking for...' -li -r Path/To/Folder/Containing/Docs
This command is particularily useful if you're searching a folder full of MS Word docs. Word docs aren't plain text files (duh) and therefore don't get matched properly by most application level search features (e.g. TextWrangler).

The 'l' option is shorthand for '--files-with-matches'. Only the names of files containing selected lines are written to standard output.

The 'i' option is shorthand for '--ignore-case'. Omit this option if you do want your search to be case sensitive.

Lastly, the 'r' option is shorthand for '--recursive'. This tells grep to recursively search the subdirectories listed. This is key when you're interested in searching a folder full of docs (as opposed to an individual file).

No comments:

Post a Comment