Using Regular Expressions with grep

In addition to using grep to search for simple text strings, you can also use grep to search for regular expressions. Regular expressions are kind of like fancy wildcards, where you use a symbol to represent a character, number, or other symbol. With regular expressions, you can search for different parts of files, such as the end of a line or a text string next to another specified text string. Table 6.1 lists some of the more common regular expressions.

Table 6.1. Regular Expressions, Examples, and Explanations
REGULAR EXPRESSIONFUNCTIONEXAMPLEEXPLANATION
.Matches any charactergrep b.rryThis finds all instances of “berry” or “barry.”
*Matches zero or more instances of the preceding item, so a*b would find “b” ...

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.