Searching and filtering output of show command

Cisco device allows us to search and filter output of a show command. This is very useful if we need to find out or sort out some specific information through large amount of configuration.

Syntax
command | { begin | include | exclude } regular-expression

Command can be any command followed by pipe character then entering one of the keywords begin, include or exclude and the expression that we want to search.

Expression are case sensitive.

Switch# show running-config | ?
begin Begins unfiltered output of the show command with the first line
that contains the regular expression.
exclude Displays output lines that do not contain the regular expression.
include Displays output lines that contain the regular expression.

Below is the example which search configuration lines which include no and display it.

Switch# show running-config | include no
no service timestamps log datetime msec
no service timestamps debug datetime msec
no service password-encryption

Displaying configuration lines that begin with interface

Switch# show running-config | begin interface
interface FastEthernet0/1
!
interface FastEthernet0/2
!
interface FastEthernet0/3
!
interface FastEthernet0/4
!
interface FastEthernet0/5
!
interface FastEthernet0/6
!
interface FastEthernet0/7
!
interface FastEthernet0/8
!
interface FastEthernet0/9
!
interface FastEthernet0/10
!
interface FastEthernet0/11
!
interface FastEthernet0/12
!
interface FastEthernet0/13
!
interface FastEthernet0/14
!
interface FastEthernet0/15

Now, we will make FastEthernet 0/1 port admin down and exclude that port from a search result

Switch(config)#interface fastEthernet 0/1
Switch(config-if)#shut
%LINK-5-CHANGED: Interface FastEthernet0/1, changed state to administratively down
Switch(config-if)#exit
Switch# show ip int brief
Interface IP-Address OK? Method Status Protocol
FastEthernet0/1 unassigned YES manual administratively down down
FastEthernet0/2 unassigned YES manual down down
FastEthernet0/3 unassigned YES manual down down
FastEthernet0/4 unassigned YES manual down down
Switch# show ip int brief | exclude admin
Interface IP-Address OK? Method Status Protocol
FastEthernet0/2 unassigned YES manual down down
FastEthernet0/3 unassigned YES manual down down
FastEthernet0/4 unassigned YES manual down down

The above output does not contain line for interface FastEthernet0/1. Expression admin has been matched to interface FastEthernet0/1 and it has been excluded from the result.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s