1

[Cisco IOS-XE] [4507R+E]

How to exclude interfaces without description on 'sh int description' command using regex?

Couldn't find any related/previous questions.

3 Answers 3

3

First off, you should enable shell processing on your device, either by using terminal shell for current session testing or permanent enabling it by using:

#conf t
(config)#shell processing full
(config)#end
#wr
Building configuration...
[OK]

Now you can use Linux commands, like grep. You can use man grep to see the manual description of the function. show shell functions will give you a full overview of available functions on your device.

Grep can get the information you want. My show interface desc looks like:

#sh int desc
Interface                      Status         Protocol Description
Vl1                            admin down     down
Vl3                            up             up       SW_MGMT
Gi0/0                          down           down
Te1/0/1                        up             up       X10 Po11
Te1/0/2                        up             up       X10 Po12
Te1/0/3                        up             up       X11 Po13
Te1/0/4                        up             up       X11 Po14
Te1/0/5                        up             up       X12 Po15
Te1/0/6                        up             up       X13 Po16
Te1/0/7                        up             up       X13 Po17
Te1/0/8                        up             up       X14 Po18
Te1/0/9                        up             up       X15 Po19
Te1/0/10                       up             up       X15 Po20
Te1/0/11                       up             up       X16 Po21
Te1/0/12                       up             up       X21 Po22
Te1/0/13                       up             up       X21 Po23
Te1/0/14                       up             up       X22 Po24
Te1/0/15                       down           down
Te1/0/16                       down           down
Te1/0/17                       up             up       X24 Po27
Te1/0/18                       up             up       X25 Po28
Te1/0/19                       up             up       X25 Po29
Te1/0/20                       up             up       X26 Po30
Te1/0/21                       down           down     X27 Po31
Te1/0/22                       up             up       X31 Po32
Te1/0/23                       up             up       X31 Po33
Te1/0/24                       up             up       X33 Po34
Te1/1/1                        up             up       X34 Po35
Te1/1/2                        up             up       X35 Po36
Te1/1/3                        up             up       X35 Po37
Te1/1/4                        up             up       X36 Po38
Te1/1/5                        up             up       HX HotSpot Po39
Te1/1/6                        up             up       X23 Po43
Te1/1/7                        up             up       HX 6509 Po1
Te1/1/8                        up             up       X23 Po44
Fo1/1/1                        down           down
Fo1/1/2                        down           down
Te2/0/1                        up             up       X10 Po11
Te2/0/2                        up             up       X10 Po12
Te2/0/3                        up             up       X11 Po13
Te2/0/4                        up             up       X11 Po14
Te2/0/5                        up             up       X12 Po15
Te2/0/6                        up             up       X13 Po16
Te2/0/7                        up             up       X13 Po17
Te2/0/8                        up             up       X14 Po18
Te2/0/9                        up             up       X15 Po19
Te2/0/10                       up             up       X15 Po20
Te2/0/11                       up             up       X16 Po21
Te2/0/12                       up             up       X21 Po22
Te2/0/13                       up             up       X21 Po23
Te2/0/14                       up             up       X22 Po24
Te2/0/15                       down           down
Te2/0/16                       down           down     X23 Po26
Te2/0/17                       up             up       X24 Po27
Te2/0/18                       up             up       X25 Po28
Te2/0/19                       up             up       X25 Po29
Te2/0/20                       up             up       X26 Po30
Te2/0/21                       down           down     X27 Po31
Te2/0/22                       up             up       X31 Po32
Te2/0/23                       up             up       X31 Po33
Te2/0/24                       up             up       X33 Po34
Te2/1/1                        up             up       X34 Po35
Te2/1/2                        up             up       X35 Po36
Te2/1/3                        up             up       X35 Po37
Te2/1/4                        up             up       X36 Po38
Te2/1/5                        up             up       HX HotSpot Po39
Te2/1/6                        up             up       X23 Po43
Te2/1/7                        up             up       HX 6509 Po1
Te2/1/8                        up             up       X23 Po44
Fo2/1/1                        down           down
Fo2/1/2                        down           down
Po1                            up             up       Uplink
Po11                           up             up
Po12                           up             up
Po13                           up             up
Po14                           up             up
Po15                           up             up
Po16                           up             up
Po17                           up             up
Po18                           up             up
Po19                           up             up
Po20                           up             up
Po21                           up             up
Po22                           up             up
Po23                           up             up
Po24                           up             up
Po27                           up             up
Po28                           up             up
Po29                           up             up
Po30                           up             up
Po31                           down           down
Po32                           up             up
Po33                           up             up
Po34                           up             up
Po35                           up             up
Po36                           up             up
Po37                           up             up
Po38                           up             up
Po39                           up             up
Po40                           down           down
Po42                           down           down
Po43                           up             up       X23 Ny
Po44                           up             up       X23 Ny

Now i use grep to get whatever i want via regex:

#sh int desc | grep [updown].......[a-zA-Z0-9] | grep -v admin
Interface                      Status         Protocol Description
Vl3                            up             up       SW_MGMT
Te1/0/1                        up             up       X10 Po11
Te1/0/2                        up             up       X10 Po12
Te1/0/3                        up             up       X11 Po13
Te1/0/4                        up             up       X11 Po14
Te1/0/5                        up             up       X12 Po15
Te1/0/6                        up             up       X13 Po16
Te1/0/7                        up             up       X13 Po17
Te1/0/8                        up             up       X14 Po18
Te1/0/9                        up             up       X15 Po19
Te1/0/10                       up             up       X15 Po20
Te1/0/11                       up             up       X16 Po21
Te1/0/12                       up             up       X21 Po22
Te1/0/13                       up             up       X21 Po23
Te1/0/14                       up             up       X22 Po24
Te1/0/17                       up             up       X24 Po27
Te1/0/18                       up             up       X25 Po28
Te1/0/19                       up             up       X25 Po29
Te1/0/20                       up             up       X26 Po30
Te1/0/21                       down           down     X27 Po31
Te1/0/22                       up             up       X31 Po32
Te1/0/23                       up             up       X31 Po33
Te1/0/24                       up             up       X33 Po34
Te1/1/1                        up             up       X34 Po35
Te1/1/2                        up             up       X35 Po36
Te1/1/3                        up             up       X35 Po37
Te1/1/4                        up             up       X36 Po38
Te1/1/5                        up             up       HX HotSpot Po39
Te1/1/6                        up             up       X23 Po43
Te1/1/7                        up             up       HX 6509 Po1
Te1/1/8                        up             up       X23 Po44
Te2/0/1                        up             up       X10 Po11
Te2/0/2                        up             up       X10 Po12
Te2/0/3                        up             up       X11 Po13
Te2/0/4                        up             up       X11 Po14
Te2/0/5                        up             up       X12 Po15
Te2/0/6                        up             up       X13 Po16
Te2/0/7                        up             up       X13 Po17
Te2/0/8                        up             up       X14 Po18
Te2/0/9                        up             up       X15 Po19
Te2/0/10                       up             up       X15 Po20
Te2/0/11                       up             up       X16 Po21
Te2/0/12                       up             up       X21 Po22
Te2/0/13                       up             up       X21 Po23
Te2/0/14                       up             up       X22 Po24
Te2/0/16                       down           down     X23 Po26
Te2/0/17                       up             up       X24 Po27
Te2/0/18                       up             up       X25 Po28
Te2/0/19                       up             up       X25 Po29
Te2/0/20                       up             up       X26 Po30
Te2/0/21                       down           down     X27 Po31
Te2/0/22                       up             up       X31 Po32
Te2/0/23                       up             up       X31 Po33
Te2/0/24                       up             up       X33 Po34
Te2/1/1                        up             up       X34 Po35
Te2/1/2                        up             up       X35 Po36
Te2/1/3                        up             up       X35 Po37
Te2/1/4                        up             up       X36 Po38
Te2/1/5                        up             up       HX HotSpot Po39
Te2/1/6                        up             up       X23 Po43
Te2/1/7                        up             up       HX 6509 Po1
Te2/1/8                        up             up       X23 Po44
Po1                            up             up       Uplink
Po43                           up             up       X23 Ny
Po44                           up             up       X23 Ny

First i tell it to find anything with up or down. Then i tell it that the maximum white spaces are 7 followed by any character or number. The last grep will remove any admin down interfaces.

7
  • 2
    You could also just skip to column 56: grep ^.{55}[a-zA-Z0-9]. Note that grep -v admin also removes lines with e.g. interface names containing admin.
    – Zac67
    Commented Oct 10, 2019 at 15:00
  • Will test tomorrow even though i have no doubt you are correct, nice to learn a little and i didn’t have much time.
    – Cow
    Commented Oct 10, 2019 at 15:34
  • @Zac67 What interfaces on a Cisco device has interface names containing admin?
    – Cow
    Commented Oct 10, 2019 at 15:46
  • @Zac67 So ^.{55} removes 55 chars containing nothing, but keep lines containing [a-zA-Z0-9]? Correctly understood?
    – Cow
    Commented Oct 10, 2019 at 15:59
  • I totally forgot about the repetition using {}. Shame on me :-)
    – Cow
    Commented Oct 10, 2019 at 16:00
1

If you wanna do it without the shell processing (which is not accessible by TCL for example) you can do it with following command:

show interfaces description | include down[ ]+down[ ]+[A-Za-z0-9]|up[ ]+up[ ]+[A-Za-z0-9]
2
  • 1
    Hello @MarioJost, this would work for descriptions without any special characters. Example - If we use description "== Connection to Switch10 ==", the above regex would not work.
    – userx
    Commented Oct 17, 2019 at 14:17
  • @userx Then, you'd need to adjust the regex to include the value = within the brackets. Cisco does not support the use of \w .This is just a idea to achieve the result requested without using shell processing.
    – Mario Jost
    Commented Oct 22, 2019 at 12:17
0

The existing answers filter for characters in the description column, so they also drop any header or footer lines - this may not be desired.

I don't have a proper device at hand for testing, but what you actually asked for is filtering out lines that contain up or down at the end of the line:

show interface description |grep -v (up|down)$

Trailing whitespaces can also be handled by grep -v (up|down)\s*$.

You can also skip to the name column and look for any character there:

show interface description |grep ^.{55}[a-zA-Z0-9]
2
  • Hello @Zac67, ask was to find a filter that excludes any interfaces without description regardless of the switch port status.
    – userx
    Commented Oct 17, 2019 at 14:11
  • @userx Exactly - that filter should exclude any line that contains up or down follow by EOL (either directly or with only whitespaces \s in between). As noted, I can't test it for Cisco but it works with common regex implementations.
    – Zac67
    Commented Oct 17, 2019 at 14:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.