Information Technology Reference
In-Depth Information
(5)
[
range
]
matches any character in the string of characters
range
.The
following five rules must be observed:
R1:
The backslash
\
is not needed to indicate special characters in
range
.The
backslash only represents itself.
R2:
The closing bracket
]
must be the first character in
range
in order to be
recognized as itself.
R3:
Intervals of the type
a-z
,
A-Z
,
0-9
in
range
are permitted. For example,
i-m
.
R4:
The hyphen
-
must be at the beginning or the end of
range
in order to
be recognized as itself.
R5:
The carat
^
must not be the first character in
range
in order to be recog-
nized as itself.
(6)
[^
range
]
matches any character not in
range
.Therules
R1
-
R4
under
5) also apply here.
(7)
pattern
*
stands for 0 or any number of concatenated copies of
pattern
where
pattern
is a specific character, the period
.
(meaning any character) or
a range
[
...
]
as described under 5) and 6).
(8)
pattern
\{
α
,
ω
\}
stands for
α
to
ω
concatenated copies of
pattern
.If
ω
is omitted, then an arbitrarily large number of copies of
pattern
is matched.
Thus, the repitor
*
is equivalent to
\{
0
,\}
.
Regular expressions in
awk
.
Regular expressions are used in
awk
as address
patterns to select the pattern space for an action. They can also be used in
the
if
statement of
awk
to define a conditional. Regular expressions in
awk
are very similar to regular expressions in
sed
. The regular expressions that
can be used with
awk
consist of the following elements in between slashes
/
:
(1) Any non-special character matches itself as in
sed
.
(2) Special characters that otherwise have a particular function in
awk
have to be preceded by a backslash
\
in order to be understood literally as in
sed
.A
newline
character in the pattern space can be matched with
\n
.The
special characters are:
\\ \/ \^ \$ \. \[ \] \* \+ \? \( \) \| \n
.
Observe that
&
is not special in
awk
but in
sed
. In contrast,
+
and
?
are
special in
awk
serving as repitors similar to
*
. Parentheses are allowed in regu-
lar expressions in
awk
for grouping. Alternatives in regular expressions in
awk
are encoded using the vertical slash character
|
. Thus, the literal characters
\+
,
\?
,
\(
,
\)
and
\|
become special in
awk
but are not in
sed
. Note that
there is no tagging using
\(
and
\)
in
awk
.
(3)
^
resp.
$
match the beginning resp. the end of the pattern space as in
sed
.
(4)
.
matches any single character as in
sed
.
(5)
[
range
]
matches any character in the string of characters
range
.The
following five rules must be observed:
R1:
The backslash
\
is not used to indicate special characters in
range
except
for
\]
and
\\
.
R2:
The closing bracket
]
is represented as
\]
. The backslash
\
is represented
Search WWH ::
Custom Search