cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
130303
Views
221
Helpful
11
Replies
Highlighted
Beginner

How to use the pipe command include A AND B

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

2 ACCEPTED SOLUTIONS

Accepted Solutions
Highlighted
Hall of Fame Guru

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

View solution in original post

Highlighted
Participant

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

View solution in original post

11 REPLIES 11
Highlighted
Hall of Fame Guru

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

View solution in original post

Highlighted

I am not sure but somebody told me that we can use regular expressions also after pipe ?

Highlighted

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#

Highlighted

ankugarg,

This was very helpful.  I know use the following command a lot:

Switch#sho ip int bri | in ^Giga.*up.*up

Thank you for this extremely helpful information.

Highlighted
Participant

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

View solution in original post

Highlighted

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

Highlighted

Good one Ankur!

Highlighted

Sure you can.

Try something like this:

 

show vl br | include (111|222)

 

Best regards!

best regards,
Highlighted

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.

 

 

Highlighted

Felipe,

 

 What device and version of code are you running?

 

Kind Regards,
Ryan

Highlighted

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

Content for Community-Ad