Using output modifiers in the MD-CLI

Output modifiers provide support for post-processing of CLI output. Output modifiers are specified using a vertical bar (|) character. The following points apply when using output modifiers:

Using | match options

The following options are supported for use with the pipe (|) match command:

The default pattern matching is a string match. If the required pattern to match includes a space, the pattern must be delimited by quotation marks (").

Example

The following example matches on the pattern autonomous-system in the tree detail under the configure router "Base" context, and starts the display with ten lines preceding the pattern match.

[ex:/configure router "Base"]
A:admin@node-2# tree detail | match autonomous-system pre-lines 10
|   |   +-- local-preference <number>
|   |   +-- policy <reference>
|   |   +-- summary-only <boolean>
|   |   +-- tunnel-group <number>
|   +-- apply-groups <reference>
|   +-- apply-groups-exclude <reference>
+-- allow-icmp-redirect <boolean>
+-- allow-icmp6-redirect <boolean>
+-- apply-groups <reference>
+-- apply-groups-exclude <reference>
+-- autonomous-system <number>

---snip---

Using regular expressions with | match

Regular expressions (REs) used by the MD-CLI engine are delimited by apostrophes ('); for example, '.*'. REs cannot be delimited by quotation marks ("); for example, ".*" because this indicates a string match.

MD-CLI REs are based on a subset of The Open Group Base Specifications Issue 7 and IEEE Std 1003.1-2008, 2016 Edition REs, as defined in chapter 9. MD-CLI REs only support Extended Regular Expression (ERE) notation as defined in section 9.4. Basic Regular Expression (BRE) notation as defined in section 9.3 is not supported.

In ERE notation, a backslash (\) before a special character is treated as a literal character. Backslashes are not supported before ( ) or { }, as they are in BREs to indicate a bracket expression or marked expression.

Table: Special characters in extended regular expressions
Special character Description

.

Matches any single character

*

Matches the preceding expression zero or more times

?

Matches the preceding expression zero or one time

+

Matches the preceding expression one or more times

[ ]

Matches a single character within the brackets

[^]

Matches a single character not within the brackets

^

Matches the starting position

$

Matches the ending position

( )

Defines a marked subexpression

{m,n}

Matches the preceding expression at least m and not more than n times

{m}

Matches the preceding expression exactly m times

{m, }

Matches the preceding expression at least m times

{ ,n}

Matches the preceding expression not more than n times

|

Matches either expression preceding or following the |

\

Treats the following character as a match criterion

-

Separates the start and end of a range

The following examples show the use of a bracket expression as a matching list expression.

Example: Using no match expressions

The first output does not use any match expressions and therefore shows the entire output.

[/]
A:admin@node-2# show port

===============================================================================
Ports on Slot 1
===============================================================================
Port          Admin Link Port    Cfg  Oper LAG/ Port Port Port   C/QS/S/XFP/
Id            State      State   MTU  MTU  Bndl Mode Encp Type   MDIMDX
-------------------------------------------------------------------------------
1/1/1         Down  No   Ghost   8704 8704    - netw null xcme
1/1/2         Up    No   Ghost   1514 1514    - accs null xcme
1/1/3         Up    No   Ghost   1514 1514    - accs null xcme
1/1/4         Up    No   Ghost   1514 1514    - accs null xcme
1/1/5         Up    No   Ghost   1514 1514    - accs null xcme
1/1/6         Down  No   Ghost   8704 8704    - netw null xcme
1/1/7         Down  No   Ghost   8704 8704    - netw null xcme
1/1/8         Down  No   Ghost   8704 8704    - netw null xcme
1/1/9         Down  No   Ghost   8704 8704    - netw null xcme
1/1/10        Down  No   Ghost   8704 8704    - netw null xcme
1/1/11        Down  No   Ghost   8704 8704    - netw null xcme
1/1/12        Down  No   Ghost   8704 8704    - netw null xcme
1/2/1         Up    No   Ghost   8704 8704    - netw null xcme
1/2/2         Up    No   Ghost   1514 1514    - accs null xcme
1/2/3         Up    No   Ghost   1514 1514    - accs null xcme
1/2/4         Down  No   Ghost   8704 8704    - netw null xcme
Press Q to quit, Enter to print next line or any other key to print next page.

Example: Using matching list expression

In this matching list expression, a match is any single character in the bracket expression, which in this case is 1, 3, or 5.

[/]
A:admin@node-2# show port | match '1/1/[135]'
1/1/1         Down  No   Ghost   8704 8704    - netw null xcme
1/1/3         Up    No   Ghost   1514 1514    - accs null xcme
1/1/5         Up    No   Ghost   1514 1514    - accs null xcme
1/1/10        Down  No   Ghost   8704 8704    - netw null xcme
1/1/11        Down  No   Ghost   8704 8704    - netw null xcme
1/1/12        Down  No   Ghost   8704 8704    - netw null xcme

Example: Using non-matching list expression

In this non-matching list expression, a match is any single character not in the bracket expression, that is, not 1, 2, or 4.

[/]
A:admin@node-2# show port | match '1/1/[^124]'
1/1/3         Up    No   Ghost   1514 1514    - accs null xcme
1/1/5         Up    No   Ghost   1514 1514    - accs null xcme
1/1/6         Down  No   Ghost   8704 8704    - netw null xcme
1/1/7         Down  No   Ghost   8704 8704    - netw null xcme
1/1/8         Down  No   Ghost   8704 8704    - netw null xcme
1/1/9         Down  No   Ghost   8704 8704    - netw null xcme

Example: Using the range operator

The range operator (-) can be used in a matching or non-matching list expression.

[/]
A:admin@node-2# show port | match '1/1/[3-7]'
1/1/3         Up    No   Ghost   1514 1514    - accs null xcme
1/1/4         Up    No   Ghost   1514 1514    - accs null xcme
1/1/5         Up    No   Ghost   1514 1514    - accs null xcme
1/1/6         Down  No   Ghost   8704 8704    - netw null xcme
1/1/7         Down  No   Ghost   8704 8704    - netw null xcme
[/]
A:admin@node-2# show port | match '1/1/[^3-7]'
1/1/1         Down  No   Ghost   8704 8704    - netw null xcme
1/1/2         Up    No   Ghost   1514 1514    - accs null xcme
1/1/8         Down  No   Ghost   8704 8704    - netw null xcme
1/1/9         Down  No   Ghost   8704 8704    - netw null xcme
1/1/10        Down  No   Ghost   8704 8704    - netw null xcme
1/1/11        Down  No   Ghost   8704 8704    - netw null xcme
1/1/12        Down  No   Ghost   8704 8704    - netw null xcme

Example: Using the alternation operator

The alternation operator (|) can be used with or without a bracket expression to match against two or more alternative expressions.

[/]
A:admin@node-2# show port | match '1/1/[2-5|7-9]'
1/1/2         Up    No   Ghost   1514 1514    - accs null xcme
1/1/3         Up    No   Ghost   1514 1514    - accs null xcme
1/1/4         Up    No   Ghost   1514 1514    - accs null xcme
1/1/5         Up    No   Ghost   1514 1514    - accs null xcme
1/1/7         Down  No   Ghost   8704 8704    - netw null xcme
1/1/8         Down  No   Ghost   8704 8704    - netw null xcme
1/1/9         Down  No   Ghost   8704 8704    - netw null xcme

Example: Using no bracket expression

Without a bracket expression, an exact match is attempted against two or more alternative expressions.

*[ex:/configure card 1]
A:admin@node-2# info | match '10g|100g'
        mda-type imm4-10gb-xp-xfp
        mda-type cx2-100g-cfp

MD-CLI REs match on the output format of an element, as is shown in the configuration. For example, if the value of an element is shown in hexadecimal in info output, a decimal RE does not match the value.

Example: Using special characters

MD-CLI REs are not implicitly anchored. The ^ or $ anchoring special characters can be used, as in the following example.

*[ex:/configure router "Base" bgp]
A:admin@node-2# info
    group "external" {
    }
    group "internal" {
    }
    neighbor 192.168.10.1 {
        group "external"
        keepalive 30
        peer-as 100
    }
    neighbor 192.168.10.2 {
        group "external"
        peer-as 100
        family {
            ipv4 true
        }
    }

Example: Using the anchor character preceded by four spaces

This example uses the ^ anchor character to match on "group" preceded by four spaces at the beginning of the line.

*[ex:/configure router "Base" bgp]
A:admin@node-2# info | match '^    group' pre-lines 1
    group "external" {
    }
    group "internal" {

Example: Using the anchor character preceded by eight spaces

This example uses the ^ anchor character to match on "group" preceded by eight spaces at the beginning of the line.

*[ex:/configure router "Base" bgp]
A:admin@node-2# info | match '^        group' pre-lines 1
    neighbor 192.168.10.1 {
        group "external"
    neighbor 192.168.10.2 {
        group "external"
*[ex:/configure router "Base" bgp]
A:admin@node-2#

Example: Using the compare command

In the following configuration example using the compare command, the | match option filters out those commands to be deleted (configuration statements beginning with the minus sign (-)) and those to be added (configuration statements beginning with the plus sign (+)).

*[ex:/configure log accounting-policy 5]
A:admin@node-2# /compare
+   admin-state enable
-   collection-interval 105
+   collection-interval 75
-   include-system-info true
+   include-system-info false

*[ex:/configure log accounting-policy 5]
A:admin@node-2# /compare | match '^-'
-   collection-interval 105
-   include-system-info true

Example: Using the backslash

The backslash (\) is used to match the literal "+" character that denotes additions to the configuration seen in the compare command.

*[ex:/configure log accounting-policy 5]
A:admin@node-2# /compare | match '^\+'
+   admin-state enable
+   collection-interval 75
+   include-system-info false

A character class expression is expressed as a character class name enclosed within bracket colon ("[:" and ":]") delimiters.

Character class expressions must be enclosed within brackets. The expression ‛[[:digit:]]’ is treated as an RE containing the character class ‟digit”, while ‛[:digit:]’ is treated as an RE matching ‟:”, ‟d”, ‟i”, ‟g”, or ‟t”.

Collating symbols and equivalence classes are not supported in MD-CLI REs.

Table: Character class expressions
Character class Characters matched1 Description

[:alnum:]

‛ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz 0123456789’

Alphanumeric characters

[:alpha:]

‛ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz’

Alphabetic characters

[:blank:]

‛ \t’

Space and Tab

[:cntrl:]

‛\007\b\t\n\v\f\r\1\2\3\4\5\6\16\17\20 \21\22\23\24\25\26\27\30 \31\32\33\34\35\36\37\177’

Control characters

[:digit:]

‛0123456789’

Digits

[:graph:]

‛ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz 0123456789 !\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~’

Visible characters

[:lower:]

‛abcdefghijklmnopqrstuvwxyz’

Lowercase letters

[:print:]

‛ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz 0123456789!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~ ’

Visible characters and the Space character

[:punct:]

‛!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~’

Punctuation characters

[:space:]

‛\t\n\v\f\r ‛

Whitespace (blank) characters

[:upper:]

‛ABCDEFGHIJKLMNOPQRSTUVWXYZ’

Uppercase letters

[:xdigit:]

‛0123456789ABCDEFabcdef’

Hexadecimal digits

Using the | count option

The | count option displays the line count of the output.

Note: Error messages are not processed by output modifiers. They are always displayed and are not affected by the count or match modifiers.
Example
[ex:/configure router "Base"]
A:admin@node-2# tree flat detail | match seamless-bfd
bfd seamless-bfd
bfd seamless-bfd peer <unicast-ipv4-address | global-unicast-ipv6-address>
bfd seamless-bfd peer <unicast-ipv4-address | global-unicast-ipv6-address> apply-groups <reference>
bfd seamless-bfd peer <unicast-ipv4-address | global-unicast-ipv6-address> apply-groups-exclude <reference>
bfd seamless-bfd peer <unicast-ipv4-address | global-unicast-ipv6-address> discriminator <number>

[ex:/configure router "Base"]
A:admin@node-2# tree flat detail | match seamless-bfd | count
Count: 5 lines

Using the | no-more option

The | no-more option displays the output with pagination disabled for the command. This option is similar to the environment more false setting that applies to all commands, where the entire output text is printed without page interruptions.

Using the | reverse-dns option

The | reverse-dns option performs a reverse DNS lookup on any IPv4 or IPv6 address in the input to the output modifier. The result of the lookup is inserted as the next line in the output on each line where an IP address is identified. If no match is found, no additional output is printed.

Example
[/]
A:admin@node-2# ping 10.184.216.34 | reverse-dns
PING 10.184.216.34 56 data bytes
  (10.184.216.34) www.example.com
64 bytes from 10.184.216.34: icmp_seq=1 ttl=61 time=82.4ms.
64 bytes from 10.184.216.34: icmp_seq=2 ttl=61 time=82.5ms.
64 bytes from 10.184.216.34: icmp_seq=3 ttl=61 time=82.4ms.
64 bytes from 10.184.216.34: icmp_seq=4 ttl=61 time=82.3ms.
64 bytes from 10.184.216.34: icmp_seq=5 ttl=61 time=82.2ms.

---- 10.184.216.34 PING Statistics ----
  (10.184.216.34) www.example.com
5 packets transmitted, 5 packets received, 0.00% packet loss
round-trip min = 82.2ms, avg = 82.4ms, max = 82.5ms, stddev = 0.122ms

Using the file redirect option

The > option can be used to redirect output to a local or remote file. The > redirect must be specified at the end of a command and cannot be combined with other redirects.

Example
[ex:/configure router "Base"]
A:admin@node-2# info detail | match leak-export > ?

 [url] <string>
 <string>  - <1..199 characters>

    Location to save the output

[ex:/configure router "Base"]
A:admin@node-2# info detail | match leak-export > cf3:leak-export.cfg
1 Characters matching the character class are delimited by apostrophes (')