Search Text Files for a Particular Word or Phrase

Note that you use quotation marks around your phrase because you are searching for a phrase. If you're searching for a word, you don't need quotation marks.

To search in a directory of text files for the phrase "Libby the dog", try this:

grep "Libby the dog" *.txt

By default, grep searches are case-sensitive. If you grep for "dog", you will NOT see results for "Dog". To search in a directory of text files for the word "dog" or "Dog", try this:

grep -i dog *.txt

To search in a directory of text files for word "dog" or "Dog" and thenautomatically have the results of that search entered into a text file called"dogsearch.txt", try this:

grep -i dog *.txt > dogsearch.txt

To find out how many times the word "dog" is used in a text file, try this:

grep -c dog file.txt

WebSanity Top Secret