Skip to Main Content
Linux in a Nutshell, Fourth Edition
book

Linux in a Nutshell, Fourth Edition

by Ellen Siever, Stephen Figgins, Aaron Weber
June 2003
Beginner to intermediate content levelBeginner to intermediate
944 pages
43h 1m
English
O'Reilly Media, Inc.
Content preview from Linux in a Nutshell, Fourth Edition

Examples of Searching

When used with grep or egrep, regular expressions are normally surrounded by quotes to avoid interpretation by the shell. (If the pattern contains a $, you must use single quotes, as in '$200', or escape the $, as in "\$200“.) When used with ed, vi, sed, and gawk, regular expressions are usually surrounded by / (although any delimiter works). Here are some sample patterns:

Pattern

Matches

bag

The string “bag”

^bag

“bag” at beginning of line or string

bag$

“bag” at end of line or string

^bag$

“bag” as the only text on line

[Bb]ag

“Bag” or “bag”

b[aeiou]g

Second character is a vowel

b[^aeiou]g

Second character is not a vowel

b.g

Second character is any character except newline

^...$

Any line containing exactly three characters

^\.

Any line that begins with a dot

^\.[a-z][a-z]

Same, followed by two lowercase letters (e.g., troff requests)

^\.[a-z]\{2\}

Same as previous (grep or sed only)

^[^.]

Any line that doesn’t begin with a dot

bugs*

“bug”, “bugs”, “bugss”, etc

"word"

The string “word” in quotes

"*word"*

The string “word”, with or without quotes

[A-Z][A-Z]*

One or more uppercase letters

[A-Z]+

Same (egrep or gawk only)

[A-Z].*

An uppercase letter, followed by zero or more characters

[A-Z]*

Zero or more uppercase letters

[a-zA-Z]

Any letter

[0-9A-Za-z]+

Any alphanumeric sequence

egrep or gawk pattern

Matches

[567]

One of the numbers 5, 6, or 7

five|six|seven ...

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.
Start your free trial

You might also like

Linux in a Nutshell, 6th Edition

Linux in a Nutshell, 6th Edition

Ellen Siever, Stephen Figgins, Robert Love, Arnold Robbins
Linux in Action

Linux in Action

David Clinton
Hands-On System Programming with Linux

Hands-On System Programming with Linux

Kaiwan N. Billimoria, Tigran Aivazian
Embedded Linux for Developers

Embedded Linux for Developers

Alexandru Vaduva, Alex González, Chris Simmonds

Publisher Resources

ISBN: 0596004826