cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
13107
Views
6
Helpful
8
Replies

pipe command usage

jimmyc_2
Level 1
Level 1

I would like to skim through my show run command, and grep out only the "interface" and whether "bpduguard enabled" on that interface. Something like:

sh run | incl (interface | bpduguard)

thanks

jimmyc

1 Accepted Solution

Accepted Solutions

Hi,

It works because the second pipe is taken as an alternation character (i.e. "OR") so what happens is that for each line in the config the parser searches for either "interface" or "bpduguard" and prints out a match if it finds either one.

See the chapter "Using the IOS CLI" in the configuration fundamentals book:

http://www.cisco.com/en/US/products/ps6350/products_configuration_guide_chapter09186a008044036c.html#wp1002025

It also works for multiple pipes, e.g. "show run | include interface | duplex | speed"

HTH

Andrew.

View solution in original post

8 Replies 8

Joe Clarke
Cisco Employee
Cisco Employee

If your device is running 12.3(2)T or higher (or 12.2(18)SXF5 or 12.2(40)SE or higher), you can use tclsh to do this. For example:

proc find_matching_ints { cmd } {

set output [exec "show run"]

set ints [list]

set currint ""

foreach line [split $output "\n"] {

if { [regexp {^interface (.*)$} $line ignore interface] } {

set currint [string trim $interface]

}

if { [regexp "^\\s+$cmd\[\\r\\n\]?$" $line] } {

lappend ints $currint

}

}

foreach int [lsort -unique $ints] {

puts $int

}

}

find_matching_ints "bpduguard enable"

Hi Joe

This question has come up quite a few times. Do you know if Cisco have any plans to extend their regex syntax to include things such as matching across lines etc. It would be a very useful function if they did.

Alternatively it would be almost as useful if you could use multiple pipes eg

sh run | begin interface | include bpduguard

Jon

Joe

Actually that pipe example wouldn't work but still multiple pipes would be useful for other things.

Jon

I haven't heard of any plans to add multiple pipe support or context matching support. The thought may be that TCL is coming to all platforms eventually, and it will offer a broader flexibility.

I tried something that worked, I don't know how or why. Here is the exact syntax:

sh run | incl interface | bpduguard

I would have expected that I would be required to use parentheses, like my earlier example.

Version = Cat4507 12.2(25)EWA8

Hi,

It works because the second pipe is taken as an alternation character (i.e. "OR") so what happens is that for each line in the config the parser searches for either "interface" or "bpduguard" and prints out a match if it finds either one.

See the chapter "Using the IOS CLI" in the configuration fundamentals book:

http://www.cisco.com/en/US/products/ps6350/products_configuration_guide_chapter09186a008044036c.html#wp1002025

It also works for multiple pipes, e.g. "show run | include interface | duplex | speed"

HTH

Andrew.

Hi Andrew,

I could not find that paragraph that explains where the "|" is equal to "or". Can you point me specifically to that text.

thanks.

Never mind, it was right there under alternation character, just like you said. Why can't Cisco use English, and say "or" instead of alternation character?!!!

Thanks for your help.

Jimmyc

Getting Started

Find answers to your questions by entering keywords or phrases in the Search bar above. New here? Use these resources to familiarize yourself with the community: