grep

The grep utility is used for searching for regular expressions in files. There are many variants of the grep command. In its most simple form

grep mypattern myfiles

will find mypattern in the set of myfiles.

For example,

grep "garlic" recipes/*.txt

will check for the word "garlic" in every text file in the recipes directory.

Dr Ward often uses grep as part of a pipeline. For instance, if there is a large directory that contains a mix of csv and pdf and txt files, and we want to see all of the files except the pdf files, we can use grep -v which will exclude the lines with the specified pattern, like this:

ls | grep -v ".pdf"