Using grep

The grep command lets you locate the lines in a file that contain a particular word or a phrase. The word grep is short for globally regular expression print. The command is derived from a feature of the original UNIX text editor, ed. To find a word in ed, the following command was used:

g/word/p

Here word is a regular expression. For those readers who are not familiar with regular expressions, Chapter 16, “Filtering Text Using Regular Expressions,” discusses them in detail. This particular ed command was used widely in shell scripts, thus it was factored into its own command called grep. In this section, you will look at the grep command along with some of its most commonly used options.

Looking for Words

The basic syntax of the ...

Get Sams Teach Yourself Shell Programming in 24 Hours, Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.