How to write regular expression to display connected interfaces in blade 4

What regular expression would show every connected interface on blade 4?

"show interfaces status | include connected|Gi4/" does not work because it displays either connected or Gi4/.

What character performs the "and" function in a reg express?

Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

kaufmed đź‘˝Commented:
There isn't really an "and" in regular expression. You essentially write all of the terms you want to find, and if they can occur in any order, then you must provide each permutation via alternation ( | ). For example, to find those terms above in any order, you could do:

show interfaces status.*include connected.*Gi4|show interfaces status.*Gi4.*include connected|include connected.*show interfaces status.*Gi4|include connected.*Gi4.*show interfaces status|Gi4.*show interfaces status.*include connected|Gi4.*include connected.*show interfaces status

Open in new window

As you may see, the number of options increases by n! each time you add a new option. I know zip about Cisco and their software, but if you have the ability to add multiple "rules" or whatever they call them, it would be much easier than the above.
Dragon0x40Author Commented:
This is the syntax of the Cisco switch command line interface. The regular expression can be combined with begin, exclude or include.

show interfaces status | ?
  append    Append redirected output to URL (URLs supporting append operation only)
  begin     Begin with the line that matches
  exclude   Exclude lines that match
  format    Format the output using the specified spec file
  include   Include lines that match
  redirect  Redirect output to URL
  tee       Copy output to URL

show interfaces status | include ?
  LINE  Regular Expression

If I type in what you gave me it gives me an error at the "."

show interfaces status .*include connected.*Gi4
% Invalid input detected at '^' marker.

Here is an example of regular expressions that work:

show interfaces status | include Gi1/10|Gi1/12

Gi1/10                       notconnect   97           auto   auto 10/100/1000-TX
Gi1/12                       notconnect   97           auto   auto 10/100/1000-TX

sh inv raw | include Base.[XH]|10Gbase|BaseT|(SN: [AFO])|10GB|X2

PID: WS-xxxxxx-E       , VID: V03  , SN: Fxxxxxxxxxx
NAME: "Linecard(slot 1)", DESCR: "10/100/1000BaseT (RJ45)V with 48 10/100/1000 baseT voice power ports (Cisco/IEEE)"
NAME: "Linecard(slot 5)", DESCR: "Supervisor xxxxx with x 10GE X2 ports, and x 1000BaseX SFP ports"
PID: xxxxxxxxxx   , VID: V04  , SN: Axxxxxxxxxx
kaufmed đź‘˝Commented:
If I type in what you gave me it gives me an error at the "."
I imagine it would. I misinterpreted that particular string was part of the actual command. You said "regular expression," so I thought the whole string was your regex. Sorry for that.

I'm afraid I'm out of my element on this one. I saw "regular expression" and thought I could help you. If I had access to a Cisco switch, I could probably muddle my way through it, but I'm officially a programmer, and they don't let me near the things with all the blinky lights at work. My apologies  : \
Determine the Perfect Price for Your IT Services

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden with our free interactive tool and use it to determine the right price for your IT services. Download your free eBook now!


show interfaces status | include connected.*Gi4/
Dragon0x40Author Commented:
It did not work

Gi4/18                       connected    81         a-full a-1000 10/100/1000-TX
Gi4/45                       connected    29         a-full  a-100 10/100/1000-TX
Gi4/47                       connected    13         a-full a-1000 10/100/1000-TX
Gi4/48                       connected    33         a-full   a-10 10/100/1000-TX
switch#show interfaces status | include connected.*Gi4/
Oh, cuz "Gi4" is BEFORE "connected" on each line.

So you want:

show interfaces status | include Gi4/.*connected

Dragon0x40Author Commented:
Works perfect!

#show interfaces status | include Gi4/.*connected
Gi4/18                       connected    97         a-full a-1000 10/100/1000-TX
Gi4/45                       connected    97         a-full  a-100 10/100/1000-TX
Gi4/48                       connected    97         a-full   a-10 10/100/1000-TX

can you walk me through the logic. * is any number of characters and the "." means line starts with what precedes the "."?
The period means "one of any character.". The asterisk means "zero or more of the thing immediately prior to me."

So the regular expression was in essence:

Gi4/ followed by zero or more of anything followed by connected.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Dragon0x40Author Commented:
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.