Finding text with grep

You can search through multiple files for specific strings of characters and then view the resulting list of matching files onscreen. You do this using the grep command (which stands for "global regular expression print"), as shown in Code Listing 6.7. As we'll show you in the following steps, you can add several flags to grep to get slightly different results.

To find text strings with grep:

1.
grep bucket limericks
At the shell prompt, type grep, the text you're trying to locate (in this case, bucket), and the file you're searching in (here, limericks). grep will return all lines in the file that contain the specified string, as shown in Code Listing 6.7.
2.
grep -5 bucket limericks
You can specify that a number of ...

Get Unix: Visual QuickStart Guide 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.