To all show and more commands (except show technical support) an output modifier may be added as follows:
<show/more command> | <output-modifier> <regular-expression-pattern>
The output modifiers are:
-
begin: Start output from the first line that has a sequence of characters matching thegiven regular expression pattern
-
include: Includes only lines that have a sequence of characters matching the given regular expression pattern.
-
exclude: Excludes all lines that have a sequence of characters matching the given regular expression pattern.
-
count: Counts all lines that have a sequence of characters matching the given regular expression pattern and displays the result
(no other output is displayed).
Note
|
Only 1 output modifier can be used in each command. The remainder of the text typed in is part of the regular expression pattern.
A regular expression is a pattern (a phrase, number, or more complex pattern). The CLI String Search feature matches regular
expressions to the show or more command output. Regular expressions are case-sensitive and allow for complex matching requirements.
A regular expression can be a single-character pattern or a multiple-character pattern. That is, a regular expression can
be a single character that matches the same single character in the command output or multiple characters that match the same
multiple characters in the command output. The pattern in the command output is referred to as a string. This section describes
creating both single-character patterns and multiple-character patterns. It also discusses creating more complex regular expressions,
using multipliers, alternation, anchoring, and parentheses.
|
Single-Character Patterns
The simplest regular expression is a single character that matches the same single character in the command output. You can
use any letter (A-Z, a-z) or digit (0-9) as a single-character pattern. You can also use other keyboard characters (such as
! or ~) as single-character patterns, but certain keyboard characters have special meaning when used in regular expressions.
The following table lists the keyboard characters that have special meanings
Character
|
Meaning
|
.
|
Matches any single character, including white space.
|
*
|
Matches 0 or more sequences of the pattern.
|
+
|
Matches 1 or more sequences of the pattern.
|
?
|
Matches 0 or 1 occurrences of the pattern.
|
^
|
Matches the beginning of the string.
|
$
|
Matches the end of the string.
|
To use these special characters as single-character patterns, remove the special meaning by preceding each character with
a backslash (\).
The following examples are single-character patterns matching a dollar sign, an underscore, and a plus sign, respectively.
\$ \_ \+
You can specify a range of single-character patterns to match against command output. For example, you can create a regular
expression that matches a string containing one of the following letters: a, e, i, o, or u. Only one of these characters must
exist in the string for pattern matching to succeed. To specify a range of single-character patterns, enclose the single-character
patterns in square brackets ([ ]). For example, [aeiou] matches any one of the five vowels of the lowercase alphabet, while
[abcdABCD] matches any one of the first four letters of the lower- or uppercase alphabet.
You can simplify ranges by entering only the endpoints of the range separated by a dash (-).
Simplify the previous range as follows:
[a-dA-D]
To add a dash as a single-character pattern in your range, include another dash and precede it with a backslash:
[a-dA-D\-]
You can also include a right square bracket (]) as a single-character pattern in your range, as shown here:
[a-dA-D\-\]]
The previous example matches any one of the first four letters of the lower- or uppercase alphabet, a dash, or a right square
bracket. You can reverse the matching of the range by including a caret (^) at the start of the range. The following example
matches any letter except the ones listed:
[^a-dqsv]
The following example matches anything except a right square bracket (]) or the letter d:
[^\]d]
Multiple-Character Patterns
When creating regular expressions, you can also specify a pattern containing multiple characters. You create multiple-character
regular expressions by joining letters, digits, or keyboard characters that do not have special meaning. For example, a4%
is a multiple-character regular expression.
With multiple-character patterns, order is important. The regular expression a4% matches the character a followed by a 4 followed
by a % sign. If the string does not have a4%, in that order, pattern matching fails. The multiple-character regular expression
a. uses the special meaning of the period character to match the letter a followed by any single character. With this example,
the strings ab, a!, or a2 are all valid matches for the regular expression.
You can remove the special meaning of the period character by inserting a backslash before it. For example, when the expression
a\. is used in the command syntax, only the string a. will be matched.
You can create a multiple-character regular expression containing all letters, all digits, all keyboard characters, or a combination
of letters, digits, and other keyboard characters. For example, telebit 3107 v32bis is a valid regular expression.
Multipliers
You can create more complex regular expressions that instruct the system to match multiple occurrences of a specified regular
expression. To do so, use some special characters with your single-character and multiple-character patterns. Table 1 lists
the special characters that specify multiples of a regular expression.
Table 1. Table 1: Special Characters Used as Multipliers
Character
|
Description
|
*
|
Matches 0 or more single-character or multiple-character patterns.
|
+
|
Matches 1 or more single-character or multiple-character patterns.
|
?
|
Matches 0 or 1 occurrences of a single-character or multiple-character pattern.
|
The following example matches any number of occurrences of the letter a, including none:
a*
The following pattern requires that at least one letter a be in the string to be matched:
a+
The following pattern matches the string bb or bab:
ba?b
The following string matches any number of asterisks (*):
\**
To use multipliers with multiple-character patterns, enclose the pattern in parentheses. In the following example, the pattern
matches any number of the multiple-character string ab:
(ab)*
The following pattern matches one or more instances of alphanumeric pairs, but not none (that is, an empty string is not a
match):
([A-Za-z][0-9])+
The order for matches using multipliers (*, +, or ?) is to put the longest construct first. Nested constructs are matched
from outside to inside. Concatenated constructs are matched beginning at the left side of the construct. Thus, the regular
expression above matches A9b3, but not 9Ab3 because the letters are specified before the numbers.
Alternation
Alternation allows you to specify alternative patterns to match against a string. You separate the alternative patterns with
a vertical bar (|). Only one of the alternatives can match the string. For example, the regular expression codex|telebit either
matches the string codex or the string telebit, but not both codex and telebit.
Anchoring
You can instruct the system to match a regular expression pattern against the beginning or the end of the string. You anchor
these regular expressions to a portion of the string using the special characters shown in Table 2.
Table 2. Table 2: Special Characters Used for Anchoring
Character
|
Description
|
^
|
Matches the beginning of the string.
|
$
|
Matches the end of the string.
|
For example, the regular expression ^con matches any string that starts with con, and $sole matches any string that ends with
sole.
In addition to indicating the beginning of a string, the ^ symbol can be used to indicate the logical function not when used
in a bracketed range. For example, the expression [^abcd] indicates a range that matches any single letter, as long as it
is not the letters a, b, c, or d.