Skip to Content
sed & awk, 2nd Edition
book

sed & awk, 2nd Edition

by Dale Dougherty, Arnold Robbins
March 1997
Intermediate to advanced
432 pages
11h 31m
English
O'Reilly Media, Inc.
Content preview from sed & awk, 2nd Edition

A Line-Up of Characters

We have seen two basic elements in an expression:

  1. A value expressed as a literal or a variable.

  2. An operator.

A regular expression is made up of these same elements. Any character, except the metacharacters in Table 3.1, is interpreted as a literal that matches only itself.

Table 3.1. Summary of Metacharacters
Special CharactersUsage
.

Matches any single character except newline. In awk, dot can match newline also.

*

Matches any number (including zero) of the single character (including a character specified by a regular expression) that immediately precedes it.

[...]

Matches any one of the class of characters enclosed between the brackets. A circumflex (^) as first character inside brackets reverses the match to all characters except newline and those listed in the class. In awk, newline will also match. A hyphen (-) is used to indicate a range of characters. The close bracket (]) as the first character in class is a member of the class. All other metacharacters lose their meaning when specified as members of a class.

^

First character of regular expression, matches the beginning of the line. Matches the beginning of a string in awk, even if the string contains embedded newlines.

$

As last character of regular expression, matches the end of the line. Matches the end of a string in awk, even if the string contains embedded newlines.

\{n,m\}

Matches a range of occurrences of the single character (including a character specified by a regular expression) ...

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

The AWK Programming Language, 2nd Edition

The AWK Programming Language, 2nd Edition

Alfred V. Aho, Brian W. Kernighan, Peter J. Weinberger

Publisher Resources

ISBN: 1565922255Supplemental ContentErrata Page