Using GREP CLI show command filters

Use the following GREP filters to output only the command lines specified by the filter.

Procedure

  1. Count the number of lines in the output:

    <CLI command> | count

  2. Display the output of a command starting from the first line that matches the given pattern:

    <CLI command> | begin WORD<0–255> [field <number>] [ignore-case] [header <number>]

  3. Display only the output lines that match the given pattern:

    <CLI command> | include <pattern> [field <number>] [ignore-case] [header <number>]

  4. Display only the output lines that do not match the given pattern:

    <CLI command> | exclude <pattern> [field <number>] [ignore-case] [header <number>]

  5. Temporarily disable pagination for the output of a CLI command:

    <CLI command> | no-more

    There is no prompt to continue or to quit when the lines of output exceed the terminal length.

  6. Limit the output of a command to the first few lines:

    <CLI command> | head [<number>]

    If a number is not specified, the first 10 lines display.

  7. Limit the output of a command to the last few lines:

    <CLI command> | tail [<number>] [from-line <number>] [header <number>]

    If a number is not specified, the last 10 lines display.

Example

Switch:1>enable
Siwtch:1#configure terminal

Count the number of lines in the output:

Switch1:#show vlan basic | count
Count: 17 lines 

Display only the output lines that match the given pattern:

Switch:1(config)#show vlan basic | include byPort field 3 header 6

======================================================================================================
                                            Vlan Basic
======================================================================================================
VLAN                                MSTP
ID    NAME             TYPE         INST_ID PROTOCOLID   SUBNETADDR      SUBNETMASK  VRFID   ORIGIN
--------------------------------------------------------------------------------------------------------
1     Default          byPort       0       none         N/A             N/A          0      CONFIG
3     VLAN3            byPort       3       none         N/A             N/A          0      CONFIG
4     VLAN4            byPort       4       none         N/A             N/A          0      CONFIG
5     VLAN5            byPort       5       none         N/A             N/A          0      CONFIG
8     VLAN-8           byPort       8       none         N/A             N/A          0      CONFIG
9     VLAN-9           byPort       9       none         N/A             N/A          0      CONFIG
11    VLAN-11          byPort       11      none         N/A             N/A          0      CONFIG
12    VLAN-12          byPort       12      none         N/A             N/A          0      CONFIG
20    VLAN-20          byPort       0       none         N/A             N/A          0      CONFIG
Switch:1(config)#show vlan basic | include private field 3 header 6

======================================================================================================
                                            Vlan Basic
======================================================================================================
VLAN                                MSTP
ID    NAME             TYPE         INST_ID PROTOCOLID   SUBNETADDR   SUBNETMASK   VRFID    ORIGIN
6     VLAN6            private      40      none         N/A           N/A           0      CONFIG
7     VLAN7            private      41      none         N/A           N/A           0      CONFIG

Display only the output lines that do not match the given pattern:

Switch:1(config)#show vlan basic | exclude private field 3 header 6
=======================================================================================================
                                            Vlan Basic
=======================================================================================================
VLAN                                MSTP
ID    NAME             TYPE         INST_ID PROTOCOLID   SUBNETADDR   SUBNETMASK  VRFID     ORIGIN
----------------------------------------------------------------------------------------------------------
1     Default          byPort       0       none         N/A           N/A          0        CONFIG
3     VLAN3            byPort       3       none         N/A           N/A          0        CONFIG
4     VLAN4            byPort       4       none         N/A           N/A          0        CONFIG
5     VLAN5            byPort       5       none         N/A           N/A          0        CONFIG
8     VLAN-8           byPort       8       none         N/A           N/A          0        CONFIG
9     VLAN-9           byPort       9       none         N/A           N/A          0        CONFIG
11    VLAN-11          byPort       11      none         N/A           N/A          0        CONFIG
12    VLAN-12          byPort       12      none         N/A           N/A          0        CONFIG
20    VLAN-20          byPort       0       none         N/A           N/A          0        CONFIG

Switch:1(config)#show vlan basic | exclude byPort field 3 header 6

=======================================================================================================
                                            Vlan Basic
=======================================================================================================
VLAN                                MSTP
ID    NAME             TYPE         INST_ID PROTOCOLID   SUBNETADDR   SUBNETMASK   VRFID   ORIGIN
-------------------------------------------------------------------------------------------------------
6     VLAN6            private      40      none         N/A           N/A           0      CONFIG
7     VLAN7            private      41      none         N/A           N/A           0      CONFIG

Display the output of a command starting from the first line that matches the given pattern:

Switch:1(config)#show vlan basic | begin 8 header 6

======================================================================================================
                                            Vlan Basic
======================================================================================================
VLAN                                MSTP
ID    NAME             TYPE         INST_ID PROTOCOLID   SUBNETADDR   SUBNETMASK   VRFID  ORIGIN
8     VLAN-8           byPort       8       none         N/A           N/A          0      CONFIG
9     VLAN-9           byPort       9       none         N/A           N/A          0      CONFIG
11    VLAN-11          byPort       11      none         N/A           N/A          0      CONFIG
12    VLAN-12          byPort       12      none         N/A           N/A          0      CONFIG
20    VLAN-20          byPort       0       none         N/A           N/A          0      CONFIG

Display the entire output of the command:

Switch:1(config)#show vlan basic | no-more

===============================================================================================
                                            Vlan Basic
================================================================================================
VLAN                                MSTP
ID    NAME             TYPE         INST_ID PROTOCOLID   SUBNETADDR   SUBNETMASK  VRFID  ORIGIN
-------------------------------------------------------------------------------------------------
1     Default          byPort       0       none         N/A           N/A          0     CONFIG
3     VLAN3            byPort       3       none         N/A           N/A          0     CONFIG
4     VLAN4            byPort       4       none         N/A           N/A          0     CONFIG
5     VLAN5            byPort       5       none         N/A           N/A          0     CONFIG
6     VLAN6            private      40      none         N/A           N/A          0     CONFIG
7     VLAN7            private      41      none         N/A           N/A          0     CONFIG
8     VLAN-8           byPort       8       none         N/A           N/A          0     CONFIG
9     VLAN-9           byPort       9       none         N/A           N/A          0     CONFIG
11    VLAN-11          byPort       11      none         N/A           N/A          0     CONFIG
12    VLAN-12          byPort       12      none         N/A           N/A          0     CONFIG
20    VLAN-20          byPort       0       none         N/A           N/A          0     CONFIG

Display only the first few lines of output:

Switch:1(config)#show vlan basic | head 9

===================================================================================================
                                            Vlan Basic
===================================================================================================
VLAN                                MSTP
ID    NAME             TYPE         INST_ID PROTOCOLID   SUBNETADDR  SUBNETMASK  VRFID   ORIGIN
----------------------------------------------------------------------------------------------------
1     Default          byPort       0       none         N/A          N/A          0      CONFIG
3     VLAN3            byPort       3       none         N/A          N/A          0      CONFIG

Display only the last few lines of output:

Switch:1(config)#show vlan basic | tail 8 header 6

==================================================================================================
                                            Vlan Basic
==================================================================================================
VLAN                                MSTP
ID    NAME             TYPE         INST_ID PROTOCOLID   SUBNETADDR  SUBNETMASK  VRFID   ORIGIN
8     VLAN-8           byPort       8       none         N/A          N/A         0       CONFIG
9     VLAN-9           byPort       9       none         N/A          N/A         0       CONFIG
11    VLAN-11          byPort       11      none         N/A          N/A         0       CONFIG
12    VLAN-12          byPort       12      none         N/A          N/A         0       CONFIG
20    VLAN-20          byPort       0       none         N/A          N/A         0       CONFIG
Switch:1(config)#show vlan basic | tail from-line 15 header 6

================================================================================================
                                            Vlan Basic
================================================================================================
VLAN                                MSTP
ID    NAME             TYPE         INST_ID PROTOCOLID   SUBNETADDR  SUBNETMASK  VRFID   ORIGIN
9     VLAN-9           byPort       9       none         N/A          N/A         0       CONFIG
11    VLAN-11          byPort       11      none         N/A          N/A         0       CONFIG
12    VLAN-12          byPort       12      none         N/A          N/A         0       CONFIG
20    VLAN-20          byPort       0       none         N/A          N/A         0       CONFIG

Variable definitions

The GREP filters use the following parameters:

Parameter

Description

field<number>

Specifies the field in each line to match against the pattern. Fields are separated by white spaces and are counted starting with 1 for the left-most field.

If the output is formatted as a table, whitespaces are not counted as fields.

from-line <number>

Specifies the remaining output starting with a given line.

head<number>

Specifies the number of lines to keep from the beginning of the output.

header<number>

Specifies a number of lines from the start of the output to display unchanged before trying to match the pattern. This parameter is useful to keep the header of a table intact. This filter skips the header lines.

ignore-case

Specifies letters to match in the pattern regardless of case.

<number>

Specifies the number of lines of output to keep, either from the beginning of the output or from the end of the output.

<pattern>

Specifies the regular expression to match against each line of output. Use quotations if the parameter contains spaces.