cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
199147
Views
245
Helpful
12
Replies

How to use the pipe command include A AND B

pfang_eho
Level 1
Level 1

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

Jon Marshall
Hall of Fame
Hall of Fame

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

ankugarg
Level 3
Level 3

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

12 Replies 12

Jon Marshall
Hall of Fame
Hall of Fame

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

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

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#

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.

ankugarg
Level 3
Level 3

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

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

Good one Ankur!

Jochen Reinecke
Level 1
Level 1

Sure you can.

Try something like this:

 

show vl br | include (111|222)

 

Best regards!

best regards,

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.

 

 

Felipe,

 

 What device and version of code are you running?

 

Kind Regards,
Ryan

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

maurizio.s
Level 1
Level 1

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

 

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:

Review Cisco Networking products for a $25 gift card