16.12.2012 Views

z/OS V1R9.0 UNIX System Services Command ... - Christian Grothoff

z/OS V1R9.0 UNIX System Services Command ... - Christian Grothoff

z/OS V1R9.0 UNIX System Services Command ... - Christian Grothoff

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Appendix C. Regular Expressions (regexp)<br />

Many z/<strong>OS</strong> shell commands match strings of text in text files using a type of pattern<br />

known as a regular expression. A regular expression lets you find strings in text files<br />

not only by direct match, but also by extended matches, similar to, but much more<br />

powerful than the filename patterns described in sh.<br />

The newline character at the end of each input line is never explicitly matched by<br />

any regular expression or part thereof.<br />

expr and ed take basic regular expressions; all other shell commands accept<br />

extended regular expressions. grep and sed accept basic regular expressions, but<br />

will accept extended regular expressions if the –E option is used.<br />

Regular expressions can be made up of normal characters or special characters,<br />

sometimes called metacharacters. Basic and extended regular expressions differ<br />

only in the metacharacters they can contain.<br />

The basic regular expression metacharacters are:<br />

¬ $ . * \( \) [ \{ \} \<br />

The extended regular expression metacharacters are:<br />

| ¬ $ . * + ? ( ) [ { } \<br />

These have the following meanings:<br />

. A dot character matches any single character of the input line.<br />

¬ The ¬ character does not match any character but represents the beginning<br />

of the input line. For example, ¬A is a regular expression matching the letter<br />

A at the beginning of a line. The ¬ character is only special at the beginning<br />

of a regular expression, or after a ( or |.<br />

$ This does not match any character but represents the end of the input line.<br />

For example, A$ is a regular expression matching the letter A at the end of<br />

a line. The $ character is only special at the end of a a regular expression,<br />

or before a ) or |.<br />

[bracket-expression]<br />

A bracket expression enclosed in square brackets is a regular expression<br />

that matches a single character, or collation element. This bracket<br />

expression applies not only to regular expressions, but also to pattern<br />

matching as performed by the fnmatch() function (used in filename<br />

expansion).<br />

v If the initial character is a circumflex (o), then this bracket expression is<br />

complemented. It matches any character or collation-element except for<br />

the expressions specified in the bracket expression. For pattern<br />

matching, as performed by the fnmatch function, this initial character is<br />

instead ! (the exclamation mark).<br />

v If the first character after any potential circumflex is either a dash (-), or<br />

a closing square bracket (]), then that character matches exactly that<br />

character—that is, a literal dash or closing square bracket.<br />

v You can specify collation sequences by enclosing their name inside<br />

square brackets and periods. For example, [.ch.] matches the<br />

multicharacter collation sequence ch (if the current language supports<br />

© Copyright IBM Corp. 1996, 2007 885

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!