Pipe (|) command

Syntax

show <COMMAND> | {
[include <pattern-string> ] |
[exclude <pattern-string> ] |
[count [<pattern-string>]] |
[begin <lines-to-display> <pattern-string> ] |
[redirect [<FILENAME>]] }

Description

The pipe (|) command filters the output of show show commands according to the criteria specified by the parameter include, exclude, count, begin, or redirect.

Command context

Manager (#)

Parameters

<COMMAND>

Specifies the portion of the command that follows the show keyword.

Examples include: running-config, vlan, and interface 1/1/1

include <pattern-sting>

Displays output that matches the <pattern-sting>.

exclude <pattern-sting>

Displays output that does not match the <pattern-sting>.

count [<pattern-sting>]

Displays the count of the number of lines that match the <pattern-sting>. If <pattern-sting> is not specified, count displays the number of lines in the command output.

begin <lines-to-display> <pattern-string>

Displays the first line that matches the <pattern-string> and the number of lines after it specified by <lines-to-display>.

For example:

switch# sh int 1/1/1 | begin 2 "1/1/1"
Interface 1/1/1 is down (Administratively down)
 Admin state is down
 State information: Administratively down
switch# 
redirect [<FILENAME>]

Redirects output to a file. You can specify the file name—without a file extension—in the <FILENAME> parameter. Optionally, you can enclose the file name in double quotes ("). If the file exists, it is overwritten. If no file name is specified, output is redirected to a file in the /tmp/ directory on the switch.

<pattern-sting>

Specifies the pattern of characters to search for in the command output. The <pattern-sting> can optionally be enclosed in double quotes ("), but must not include any of the following characters:

  • &

  • .

  • '

  • "

  • >

  • <

Authority

Administrators

Usage

  • The pipe (|) command is supported for use with the show command only.

  • You can use multiple pipe commands with a single show command.

    For example: show running-config | include "vlan" | exclude "vlan2" | count

  • Command completion by pressing the Tab key is not supported for pipe commands.

  • Using the pipe command with the page command is not supported.

Examples

In the following examples, assume that the running configuration of the switch includes the following:

Current configuration:
...
session-timeout 0
...
ssh server vrf mgmt
...
vlan 1,10
spanning-tree
interface mgmt
    no shutdown
    ip static 10.1.1.2/24
interface vlan10
The following examples show the use of the pipe command and the resulting output:
  • Show the running configuration and include lines that have the text vlan:

    switch# sh ru | include vlan
    vlan 1,10
    interface vlan10
    switch# 
  • Show the running configuration and include lines that have the text vlan with a space before it:

    switch# sh ru | include " vlan"
    interface vlan10
    switch# 
  • Show the running configuration, but exclude all lines that have the text vlan:

    switch# sh ru | exclude vlan
    Current configuration:
    ...
    session-timeout 0
    ...
    ssh server vrf mgmt
    ...
    spanning-tree
    interface mgmt
        no shutdown
        ip static 10.1.1.2/24
    switch# 
  • Show the running configuration, include lines that have the text vlan, and direct the output to the file named myfile.

    switch# sh ru | include vlan | redirect myfile
    switch:/tmp$ cat myfile
    vlan 1,10
    interface vlan10
    switch:/tmp$
    switch# 
  • In the running configuration, show the number of lines that have the text vlan:

    switch# sh ru | include vlan | count
    2
    switch# 
  • Show the running configuration, include lines that have the text vlan, and include following two lines.

    switch# sh ru | begin 2 vlan
    vlan 1,10
    spanning-tree
    interface mgmt
    interface vlan10
    switch#