Monday, March 12, 2012

Include and Exclude text strings in IOS Configuration

In many cases, Include and Exclude filterings are very useful to filter the output of a show command to match a specific expression. Filtering is especially useful, when displaying a large configuration file. In this case, it is helpful to display sections of the configuration file without having to enter multiple commands to gather the related configuration information. 

Please see ‘Show Command Section Filer’ at this URL: http://www.cisco.com/en/US/docs/ios/12_3t/12_3t2/feature/guide/gtshfltr.html
You can learn how to use this filtering expressions from the above URL.

show include
Filters show command output so that it displays only lines that contain a particular regular expression.

show exclude
Filters show command output so that it excludes lines that contain a particular regular expression.

For example, You just see the interfaces list from the configuration file with “interface”.

Catalyst6509#sho run | i interface    (= show running-config | include interface)
mls flow ip interface-full
interface Loopback0
interface Port-channel101
interface Port-channel102
interface Port-channel103
interface GigabitEthernet1/1
interface GigabitEthernet1/2
interface GigabitEthernet1/3

You may want to see the interfaces status “up” only as below.

Catalyst6509#sho ip int br | e down   (= show ip interface brief | exclude down)
Interface                  IP-Address      OK? Method Status                Protocol          
Vlan100                    10.10.100.2     YES NVRAM  up                    up      
Vlan101                    10.10.101.2     YES NVRAM  up                    up      
Vlan111                    10.10.102.2     YES NVRAM  up                    up        
GigabitEthernet1/1         unassigned      YES unset  up                    up      
GigabitEthernet1/2         unassigned      YES unset  up                    up      
GigabitEthernet1/3         unassigned      YES unset  up                    up    

You use the ‘+’, ‘-’ and ‘/’, when running a “show run” or “show start” command.
As you may guess, + sign means ‘include’, - sign means ‘exclude’ and / (slash) sign means ‘search’.

So, type +interface to get the same output as “sho run | i interface” command.
After you type the command “show run”, you just type ‘+interace’ on the screen output (it will be overlapped --More-- at the bottom of the page).

Here is more complex, but useful tip!

The ‘-’ sign is very useful if you have many Access Control Lists (ACLs) in the configuration file.
When you see the configuration file with ‘show run” command, it displays long pages due to ACL lines.
After you type the command “show run”, just type ‘-permit|deny’ on the screen output.
This type is the same output as “sho run | e permit|deny’.
With this tip, you can see the whole configuration without long ACL lines.

And ‘/’ is useful too, when you want to see specific section of the configuration file.
The forward slash (/) character lets you find the first occurrence of the given string.
For example, just type ‘/router ospf’, after you type the command “show run”.
The screen output will be jumped to ‘router ospf’ section as soon as you type ‘/router ospf’.

No comments: