Expressions Are Strings and Wildcards


graphics/awkgrpseda_icon.gif

When using the programs in this book, such as grep and vi , you provide a regular expression that the program evaluates . The command will search for the pattern you supply. The pattern could be as simple as a string or it could wildcards. The wildcards used by many programs are called meta- characters .

Table 24-1 shows a list of meta-characters and the program(s) to which they apply. Only the programs covered in this book ( awk , grep , sed , and vi ) are shown in Table 24-1. These meta-characters may be used with other programs, such as ed and egrep , as well, which are not covered in the book. Table 24-1 describes the meta-characters and their use.

Table 24-1. Meta-Characters and Programs to Which They Apply

Meta-Character

awk

grep

sed

vi

Use

.

Yes

Yes

Yes

Yes

Match any single character.

*

Yes

Yes

Yes

Yes

Match any number of the single character that precedes * .

[ ... ]

Yes

Yes

Yes

Yes

Match any one of the characters in the set [ ... ] .

$

Yes

Yes

Yes

Yes

Matches the end of the line.

^

Yes

Yes

Yes

Yes

Matches the beginning of the line.

\

Yes

Yes

Yes

Yes

Escape the special character that follows \ .

\{ n,m \}

Yes

Yes

No

No

Match a range of occurrences of a single character between n and m .

+

Yes

No

No

No

Match one or more occurrences of the preceding regular expression.

?

Yes

No

No

No

Match zero or one occurrence of the preceding regular expression.

Yes

No

No

No

The preceding or following regular expression can be matched.

()

Yes

No

No

No

Groups regular expressions in a typical parenthetical fashion.

\{ \}

No

No

No

Yes

Match a word's beginning or end.

You may want to refer to this table when regular expressions are used for one of the commands in the table.



HP-UX 11i Systems Administration Handbook and Toolkit
HP-UX 11i Systems Administration Handbook and Toolkit (2nd Edition)
ISBN: 0131018833
EAN: 2147483647
Year: 2003
Pages: 301

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net