Filtering the Output of Show Commands

The output from many show commands can be long and complicated, sometimes containing more information than you need. You can filter the output from a show command to suit your needs using a restricted version of a UNIX/Linux feature that uses a "pipe" character to direct the output of one command to be used as input for the next command.

You can include or exclude show command output that matches your specified text pattern. You can also exclude all output until a line matches the pattern, and then include all output beginning with that line.

Most show commands can be filtered, but a few, for example, show tech-support, do not allow filtering.

To filter show command output, use the following command:

show specific show command syntax | {include |exclude |begin }regexp
show specific show command syntax Specify the show command followed by the vertical bar (|) or pipe character. For example, show ports.
include Display the lines that match the regular expression.
exclude Do not display the lines that match the regular expression.
begin Display all the lines starting with the first line that matches the regular expression.
regexp The text pattern (regular expression) to match (case-sensitive), enclosed by quotation marks.

If the specified show command outputs a refreshed display, filtering the show command terminates the display without refreshing and a message appears stating this.

Definition of Regular Expression Characters shows a summary of special characters.

Click to expand in new window

Definition of Regular Expression Characters

Operator Type Examples Description
Literal characters match a character exactly a A y 6 % @ Letters, digits and many special characters match exactly
\$ \^ \+ \\ \? Precede other special characters with a \ to cancel their regex special meaning
\n \t \r Literal new line, tab, return
Anchors and assertions ^ Starts with
$ Ends with
Character groups any one character from the group [aAeEiou] Any character listed from [ to ]
[^aAeEiou] Any character except aAeEio or u
[a-fA-F0-9] Any hex character (0 to 9 or a to f)
. Any character at all
Counts apply to previous element + One or more ("some")
* Zero or more ("perhaps some")
? Zero or one ("perhaps a")
Alternation | Either, or

Flow control

The following example display the status of “flow control” on the ports of a switch:

show ports 1-2 information detail | include "(Port|Flow Control)"

The output is similar to the following:

Port: 1
			Flow Control:   Rx-Pause: Enabled       Tx-Pause: Disabled
Priority Flow Control: Disabled

Port: 2
			Flow Control:   Rx-Pause: Enabled       Tx-Pause: Disabled
Priority Flow Control: Disabled