• No results found

How to Use CLI Filtering

In document C4 CMTS Technical Manual (Page 56-62)

The CLI permits the following types of filtering:

Begin - displays output beginning with the first line that contains the text string or regular expression

Include - displays output lines that contain the text string or regular expression and excludes lines that do not contain the text string or regular expression

Exclude - displays output lines that do not contain the text string or regular expression and excludes lines that do contain the text string or regular expression

Until - displays all lines up to and including the first line that matches the given regular expression

Count - Counts the number of lines that would have been shown C4# show running-config | count

Piped line count: 1557

C4# show running-config | count include cable-mac Piped line count: 60

Page - Temporarily turns on paging, in case you have paging turned off but need it for a particular command.

The following CLI options have been added to the show and more commands:

[|{begin|include|exclude|until |count |page} [“] regular expression [“]]

To use this functionality, enter a show or more command as normal but add a space followed by the “pipe” character (|) at the end of the command line. Then add one of the keywords begin, include, exclude, until, count, or page, along with the regular expression that you want to filter or search on.

Expanded Syntax —

show <any-command> | begin <regular expression>

show <any-command> | include <regular expression>

show <any-command> | exclude <regular expression>

show <any-command> | until <regular expression>

show <any-command> | count <regular expression>

show <any-command> | page <regular expression>

more <any-command> | begin <regular expression>

more <any-command> | include <regular expression>

more <any-command> | count <regular expression>

more <any-command> | page <regular expression>

Creating Regular

Expressions Regular expressions can be a single-character pattern that matches the same character in the input string, or multiple characters that match the same multiple characters in the input string.

Special Characters You can use keyboard characters (such as ! or ~) as single-character patterns, but certain keyboard characters have special meaning when used in regular expressions. The keyboard characters that have special meaning in the CMTS are listed in the Table 2-6:

To remove the special meaning of any of the special characters listed in Table 2-6, put a backslash (\) in front of it. For example, when the expres-sion m5\. is used in the command syntax, only the string m5. will be matched.

Table 2-6: Characters with Special Meaning in Search Patterns

Character Special Meaning

. The dot matches any single character, including white space

*

The asterisk matches any number (or none) of the single character that immediately precedes it. The preceding character can also be a regular expression. E.g., since the . (dot) means any character, then .* means “match any number of any character.”

+ The plus matches 1 or more sequences of the preceding regular expression

^ The caret matches the following regular expression at the beginning of the line.

$ The dollar sign matches the end of the line.

\ The backslash allows for literal meaning of the special characters.

[ ] The brackets allow for the definitions of a set of characters to be matched. The brackets also mean the contents will be taken as a single character. (e.g. [aeiou] = any vowel)

[^ ] Search for anything in the brackets that does not include the set of characters following the caret. (e.g. [^aeiou] = any consonant)

( ) The parentheses allow for grouping and recall.

\b Indicates the beginning/end of a word.

Range A range is a sequence of characters enclosed in brackets [ ]. It normally matches any single character from the sequence. When the sequence begins with a caret (^), it matches any single character not from the rest of the sequence. When two characters in the sequence are separated by a hyphen (-), this is shorthand for the full list of ASCII characters between them. For example, [0-9] matches any decimal digit. To include a literal bracket “]” in the sequence, make it the first character, following a possible caret. To include a literal hyphen (-), make it the first or last acter. A backslash “\” followed by a single character, includes that char-acter, however, backslashes are not necessary for most special characters, as inside a range, only the “]”, “-”, and “\” characters are treated specially.

The bracket [ ] characters allow for the definitions of a set of characters to be matched. The brackets also mean the contents will be taken as a single character.

For example, the following expression matches with a, e, i, o, u:

[aeiou]

Use the hyphen (-) character inside the square brackets to mean all the characters from the character preceding the hyphen to the character following it. For example, [0-9] is the same as [0123456789]. Also, [a-f] is the same as [abcde[a-f]. The following matches a hexidecimal digit: [0-9a-f].

When using the hyphen (-), do not mix types. Examples of bad ranges NOTE include: [7-k], [&-%], [D-e]. The [D-e] is equivalent to [D-Za-e]

which is equivalent to [a-z] because the CLI is case insensitive.

Multiple-Character Patterns Regular expressions can also specify patterns containing multiple charac-ters. You create multiple-character expressions by joining letters, digits, or keyboard characters that do not have special meaning.

Order is important in multiple-character patterns. The expression m5&

matches the character m followed by a 5 followed by a & sign. If the string does not have m5&, in that order, the pattern matching fails. The multiple-character 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 expression.

Wildcard Searches To emulate a wildcard search, the expression must match any character.

For this, regular expressions use the period (.) character. For example, the following regular expression matches ARRIS followed by any single char-acter:

The asterisk (*) in the wildcard search can match with no characters or any number of characters. For example, the following regular expression does exactly the same as the wildcard pattern above:

ARRIS.*

When you use an asterisk (*), it means none, one, or more of the previous character in the pattern. In the example, the asterisk is preceded with a period, which means none, one, or more of any character.

Multipliers You can create more complex regular expressions that instruct the soft-ware to match multiple occurrences of a specified expression. Table 2-7 lists special characters that specify “multiples” of an expression.

Examples:

To match any number of occurrences of the letter m, including none:

m*

To require that at least one letter m be in the string to be matched:

m+

By enclosing the pattern in parentheses you can use multipliers with multiple-character patterns. The parentheses () characters are used to see this pattern as one character. In the following example, the pattern matches any number of the multiple-character string mn:

(mn)*

Some useful example patterns that might be helpful:

Any IP address = [0-9]+\.[0-9]+\.[0-9]+\.[0-9]+

Any MAC address = [0-9a-f][0-9a-f][0-9a-f][0-9a-f]\.[0-9a-f]

[0-9a-f][0-9a-f][0-9a-f]\.[0-9a-f][0-9a-f][0-9a-f][0-9a-f]

Alternation Alternation allows you to specify alternative patterns to match against a string. You separate the alternative patterns with a vertical bar (|). Either one of the alternatives can match the string.

Table 2-7: Special Characters Used as Multipliers

Character Special Meaning

*

The asterisk matches any number (or none) of the single character that immediately precedes it. The preceding character can also be a regular expression. E.g., since . (dot) means any character, then .* means “match any number of any character.”

+ The plus matches 1 or more sequences of the preceding regular expression

The expression “interface.*19” returns 4 results, the expression “include slot.*17” returns 2 results, and “include slot.*17 | interface.*19” returns the combination, as shown in the following examples:

C4# show running-config | include interface.*19 configure interface ethernet 19/0 ip address 10.1.50.100 255.255.255.0

configure interface system-controller 19/0 no shutdown configure interface system-controller 19/1 no shutdown configure interface system-controller 19 no shutdown C4# show running-config | include slot.*17

configure slot 17 type RCM name "RCM A"

configure snmp-server card-trap-inh slot 17 40

C4# show running-config | include slot.*17|interface.*19 configure interface ethernet 19/0 ip address

10.1.50.100 255.255.255.0

configure slot 17 type RCM name "RCM A"

configure snmp-server card-trap-inh slot 17 40

configure interface system-controller 19/0 no shutdown configure interface system-controller 19/1 no shutdown configure interface system-controller 19 no shutdown Anchoring You can match an expression pattern against the beginning or the ending

of a string. By specifying that the beginning or ending of an input string contains a specific pattern, you “anchor” these expressions to a portion of the string using the special character shown in the following table.

This is another use for the ^ symbol. In this example, the following regular Table 2-8: Special Anchoring Character

Character Description

^ The caret matches the beginning of the string

^1234

The next example shows that the following regular expression is a range that matches any single number, as long as it is not the numbers 1, 2, 3, or 4:

[^1234]

Parentheses for Recall You can use parentheses () with multiple-character regular expressions to multiply the occurrence of a pattern. You can also use parentheses around a single or multiple-character pattern to instruct the software to remember a pattern for use elsewhere in the regular expression.

To create a regular expression that recalls a previous pattern, you use parentheses to instruct memory of a specific pattern and a backslash (\) followed by an integer to reuse the remembered pattern. The integer spec-ifies the occurrence of a parentheses in the regular expression pattern. If you have more that one remembered pattern in your regular expression, then \1 uses the first remembered pattern and \2 uses the second remem-bered pattern, up to nine.

The following regular expression uses parentheses for recall:

a(.)bc(.)\1\2

This regular expression matches the letter a followed by any character (call it character #1) followed by bc, followed by any character (character

#2), followed by character #1 again, followed by character #2 again. In this way, the regular expression could match azbctzt. The software iden-tified character #1 as z and character #2 as t and then uses z and t again later in the regular expression.

As you will notice, the parentheses do not change the pattern; they only instruct the software to recall that part of the matched string.

Following is an example of advanced regular expression using double parentheses:

((19.*) (slot|interface))

In document C4 CMTS Technical Manual (Page 56-62)

Related documents