Finding Text with grep

You can search through multiple files for specific strings of characters and then view the list of matching files onscreen. You do this using the grep command (which stands for “global regular expression print,” a once useful and now rather arcane ed or vi command), as shown in Code Listing 6.7. As we’ll show you, you can add several flags to grep to get slightly different results.

Code Listing 6.7. Use grep to see all occurrences of a specific string in a file.
[ejr@hobbes manipulate]$ grep bucketlimericks
Who carried his lunch in a bucket,
[ejr@hobbes manipulate]$
Code Listing 6.8. grep can show the context around instances of the string as well.\
[ejr@hobbes manipulate]$ grep -5 bucketlimerick he strummed and ...

Get Unix Third Edition: 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.