Examples of Searching
When used with grep or
egrep, regular expressions should
be surrounded by quotes. (If the pattern contains a $, you must use single quotes; e.g.,
' pattern
'.) When used with ed, ex,
sed, and awk, regular expressions are usually
surrounded by /, although (except
for awk) any delimiter works. The
following tables show some example patterns.
|
Pattern |
What does it match? |
|
|
The string bag. |
|
|
bag at the beginning of the line. |
|
|
bag at the end of the line. |
|
|
bag as the only word on the line. |
|
|
Bag or bag. |
|
|
Second letter is a vowel. |
|
|
Second letter is a consonant (or uppercase or symbol). |
|
|
Second letter is any character. |
|
|
Any line containing exactly three characters. |
|
|
Any line that begins with a dot. |
|
|
Same, followed by two lowercase letters (e.g., troff requests). |
|
|
Same as previous, ed, grep, and sed only. |
|
|
Any line that doesn’t begin with a dot. |
|
|
bug, bugs, bugss, etc. |
|
|
A word in quotes. |
|
|
A word, with or without quotes. |
|
|
One or more uppercase letters. |
|
|
Same; egrep or awk only. |
|
|
Same as previous, POSIX egrep or awk. |
|
|
An uppercase letter, followed by zero or more characters. |
|
|
Zero or more uppercase letters. |
|
|
Any letter, either lower- or uppercase. |
|
|
Any symbol or space (not a letter or a number). |
|
|
Same, using ... |
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access