From Mac Guides

Jump to: navigation, search

grep is a Terminal command that searches text for a specified string. The search string can be straight text or regular expression


To search for a string in a file

 grep "Some search string" somefile.txt


 cat somefile.txt | grep "Some search string"

To search Adium chat logs for a specific string (which you can obviously do within Adium as well). The -R argument tells it to recurse into subdirectories.

  cd /Users/markyoung/Library/Application Support/Adium 2.0/Users/Default/Logs
  grep -R "Some Search String" *

To list all English-language words that contain no vowels (using the exclusion argument, -v, and regular expression)

 grep -vi "[aeiouy]" /usr/share/dict/words

Man Page Excerpt

Grep searches the named input FILEs (or standard input if no files are named, or the file name - is given) for lines containing a match to the given PATTERN. By default, grep prints the matching lines. In addition, two variant programs egrep and fgrep are available. Egrep is the same as grep -E. Fgrep is the same as grep -F.