Building network automation solutions

9 module online course

Start now!

IOS doesn't have Unix-style pipes

Recently one of my readers asked an interesting question:

“It looks like the second pipe character (¦) in an output filter is interpreted as an OR, not as yet another filter. How can I thus implement a filter that will match string_a AND string_b?

As explained in my IP Corner article Enhance the IOS user interface, the output filters are extensions of the show command. The first ¦ character starts the filter specification and anything after the first keyword is part of a regular expression (where ¦ means or).

To match a combination of two strings, you could either write a small Tcl script or use a more convoluted regular expression where you combine both strings into a single expression (inserting .* between them to match any intermediate set of characters). For example, to find all static host routes in your router configuration, you could use the following filter:

show running | include ip route.*255\.255\.255\.255

Note: The \. matches the dot character, whereas the . matches anything.

2 comments:

  1. Static default route will be missed with this regexp
  2. Well, the filter is supposed to match static host routes (those with the mask 255.255.255.255).
Add comment
Sidebar