09-08-2011 10:12 AM - edited 03-07-2019 02:06 AM
Hi,
I would use show pipe command to get some detailed output like show interface status | inculde text1 AND text2
For example,
"show interface status" include vlan "103" and "connected".
I tried multiple combination, it looks multi pipe only give you OR output but AND output.
Thanks in advance
Solved! Go to Solution.
09-08-2011 10:34 AM
Peng
You are right in that the pipe command does not support the AND operator. You can do multiple OR commands eg.
sh int status | include Vlan | connected
but the above would show any interfaces that began with Vlan and also any connected interfaces whether or not they were vlan interfaces.
You cannot do an AND ie. show me all vlan interfaces that are also connected
note the above is a bad example because all vlan interfaces on a L3 switch should show as connected but you get the meaning.
I asked a while back on these forums whether there were any plans to add the AND operator and was told there weren't and that probably there wouldn't be in future because IOS now supports TCL and this has a much more extensive regex engine which you can use.
Jon
09-08-2011 11:04 AM
Hi Peng,
You can use "sh int status | inc connected.*103" or "sh int status | inc 103.*connected",depending on whether connexted apperas first or 103...I think connected appears first.
Paste the output of full command if it doesn't get the required output..We will refine the regex.
-Ankur
09-08-2011 10:34 AM
Peng
You are right in that the pipe command does not support the AND operator. You can do multiple OR commands eg.
sh int status | include Vlan | connected
but the above would show any interfaces that began with Vlan and also any connected interfaces whether or not they were vlan interfaces.
You cannot do an AND ie. show me all vlan interfaces that are also connected
note the above is a bad example because all vlan interfaces on a L3 switch should show as connected but you get the meaning.
I asked a while back on these forums whether there were any plans to add the AND operator and was told there weren't and that probably there wouldn't be in future because IOS now supports TCL and this has a much more extensive regex engine which you can use.
Jon
09-08-2011 10:54 AM
I am not sure but somebody told me that we can use regular expressions also after pipe ?
09-08-2011 10:59 AM
I just tried...It works
3-mem-stack#sh ip int br | inc Port.*up
Port-channel2 unassigned YES unset up up
3-mem-stack#
11-30-2016 07:23 PM
This was very helpful. I know use the following command a lot:
Switch#sho
Thank you for this extremely helpful information.
09-08-2011 11:04 AM
Hi Peng,
You can use "sh int status | inc connected.*103" or "sh int status | inc 103.*connected",depending on whether connexted apperas first or 103...I think connected appears first.
Paste the output of full command if it doesn't get the required output..We will refine the regex.
-Ankur
09-08-2011 11:41 AM
Thanks Ankur and Jon,
You guys are QUICK, yes Regrex did the trick. THANK YOU..
01-core-A-103-20#sh int status | inc connected.*103
Gi11/15 Primary Nic SSHMDF connected 103 a-full a-1000 10/100/1000BaseT
Gi11/27 reserved for NSP D connected 103 a-full a-1000 10/100/1000BaseT
Gi11/32 SSHRSS0BU301 Red H connected 103 a-full a-100 10/100/1000BaseT
Gi11/33 SSHUAA0B0001 Red H connected 103 a-full a-100 10/100/1000BaseT
Gi11/35 Core SQL Server Ge connected 103 a-full a-1000 10/100/1000BaseT
Gi12/2 Core SQL Server Ge connected 103 full 1000 10/100/1000BaseT
Gi12/14 NetIQ Security Man connected 103 full 1000 10/100/1000BaseT
Gi12/15 DC1 Root Server connected 103 a-full a-1000 10/100/1000BaseT
01-core-A-103-20#
01-core-A-103-20#sh int status | inc 103.*connected
Gi12/16 01-CA-103-24 G1/0/ connected trunk a-full a-1000 10/100/1000BaseT
11-22-2016 05:03 PM
Good one Ankur!
01-08-2019 02:38 AM
Sure you can.
Try something like this:
show vl br | include (111|222)
Best regards!
01-08-2019 04:04 AM
Just to add to the helpful commands that have been posted.
sho interfaces status | count connected
Number of lines which match regexp = 153
sho interfaces status | count notconnect
Number of lines which match regexp = 92
sho interfaces status | count connected|notconnect
Result of both.
01-23-2019 09:22 AM
Felipe,
What device and version of code are you running?
Kind Regards,
Ryan
01-23-2019 09:38 AM
Hi Ryan,
I have tried it on the following devices with the following IOS versions.
WS-C3850-48P - Version 16.3.5b
WS-C4510R+E - Version 03.09.02.E
WS-C3750X-48 - Version 15.0(2)SE, RELEASE SOFTWARE (fc1)
WS-C2960G-8TC-L - Version 12.2(58)SE1, RELEASE SOFTWARE (fc1)
FA
04-17-2023 04:33 PM
I think I may have found an "and" option. It seems like you will get different output depending on how the command is constructed.
For example. I did the following
sh start | i priv|cable - This shows me all lines that match prive OR cable
However if I enter
sh start | i priv| cable - I get the result of pirv AND cable
privilege exec level 3 test cable-diagnostics tdr interface
privilege exec level 3 test cable-diagnostics tdr
privilege exec level 3 test cable-diagnostics
privilege exec level 3 show cable-diagnostics tdr interface
privilege exec level 3 show cable-diagnostics tdr
privilege exec level 3 show cable-diagnostics
04-30-2025 07:10 PM - edited 04-30-2025 07:31 PM
@maurizio.s It's still just a regex and not an AND condition.
The way that gets interpreted is as `priv| cable` which means it will include any line that contains either "priv" or " cable" (with the leading space), which is why it appeared to work for that specific combination with that device's configuration at that time.
The entire line after the include, section, or exclude directive is interpreted as one big regex in which any non-leading and non-trailing whitespace is respected (you can make leading and trailing whitespace match by surrounding an expression or sub-expression with parentheses).
Any additional pipe characters represent a regex OR (substitution) directive, meaning it can take the sub-expression that's on the left or the right of it. I will include an example that can be tested on any device at the end.
However, that points out an important concept: Since you can include whatever you want in your expression, coming up with a more specific regex that will naturally not include what you don't want is often possible. In this instance, you would have gotten the same output with `show run | i ( cable)`. Had there been any other lines with the sequence " cable" in them, they also would have shown up, even without "priv".
I do not know what specific regex grammar IOS(-X(E|R)) uses, but I'd assume (based on Cisco doing everything in Java) that it's either Java regex or PCRE|PCRE2. It seems to behave similarly to PCRE2, supporting most syntax I've ever tried.
Unfortunately, it does not appear to support negative lookahead/lookbehind, which would allow for exclusions of sub-expressions. It does support some directives containing the question mark, if you enter it properly and use a backslash to escape the parentheses (depending on the expression), but the (?<!) and (?!) (negative lookbehind and negative lookahead, respectively) do not appear to work in any test I've performed, as of IOS-XE 17.12.04b.
Example showing behavior of the suggested expression.
Configuration (using a banner for free-form text entry):
#show run | b banner slip-ppp
banner slip-ppp ^C
privilege something-cable-something
privilege cable-something
privilege something
cable something
cable privilege
cable something
cable privilege
privilegecable
^C
#show run | i priv| cable
privilege something-cable-something
privilege cable-something
privilege something
cable privilege
cable something
cable privilege
privilegecable
(Don't forget to remove the banner with `no banner slip-ppp`)
As you can see, any line that contained "priv" or " cable" was included, as would be expected from a regex like this.
Specifically, the `cable something` (no leading whitespace) line was excluded, since it didn't match either condition.
Discover and save your favorite ideas. Come back to expert answers, step-by-step guides, recent topics, and more.
New here? Get started with these tips. How to use Community New member guide