Cisco CLI Regular Expressions

Some common ones I use:

Look to see if VLANs 11, 12, 13, 14 are in the VLAN database:

TPA-SWA#sh vlan | inc VLAN001[01234]
10   VLAN0010                         active
11   VLAN0011                         active
12   VLAN0012                         active
13   VLAN0013                         active
14   VLAN0014                         active

Find configured static routes for 10.48.x.x, 10.102.x.x, 172.18.x.x, and 172.19.x.x:

TPA-SWA#sh run | in ^ip.route.10.(48|102)|^ip.route.172.(18|19)
ip route 10.48.230.0 255.255.255.0 172.22.200.1
ip route 10.102.150.28 255.255.255.255 172.22.200.13
ip route 10.102.160.11 255.255.255.255 172.22.200.1
ip route 10.102.160.12 255.255.255.255 172.22.200.1
ip route 172.18.200.0 255.255.255.0 172.18.200.1
ip route 172.19.200.0 255.255.255.0 172.18.200.1

Find out where something is patched in or uplinked using their description:

TPA-SWA#sh interfaces description | inc Nexus
Te1/1/1                        up             up       Nexus 5548 Core Uplink to SW A Te1/0/1
Te2/1/1                        up             up       Nexus 5548 Core Uplink to SW A Te1/0/2
Po1                            up             up       Nexus 5548 Core Uplink

Find all IP Enable interfaces:

TPA-SWA#show ip interf brief | e unassigned
Interface              IP-Address      OK? Method Status                Protocol
Vlan2                  10.65.2.1       YES manual up                    up
Vlan3                  10.65.3.1       YES manual up                    up
Vlan240                172.24.0.1      YES manual up                    up
Vlan241                172.24.1.1      YES manual up                    up
Vlan242                172.24.2.1      YES manual up                    up
Vlan243                172.24.3.1      YES manual up                    up

Find interfaces that have errors:

TPA-SWA#sh int | inc (Ethernet)|(error)|(packet)
GigabitEthernet1/0/1 is up, line protocol is up (connected)
Hardware is Gigabit Ethernet, address is 1c6a.7ad3.2181 (bia 1c6a.7ad3.2181)
5 minute input rate 0 bits/sec, 0 packets/sec
5 minute output rate 21000 bits/sec, 34 packets/sec
0 packets input, 0 bytes, 0 no buffer
0 input errors, 0 CRC, 0 frame, 0 overrun, 0 ignored
0 input packets with dribble condition detected
28125542 packets output, 2600335977 bytes, 0 underruns
0 output errors, 0 collisions, 1 interface resets

Search for either 3750 OR Version per line. So the line could have either 3750 OR Version.

TPA-SWA#show version | include 3750|Version
Cisco IOS Software, C3750E Software (C3750E-UNIVERSALK9-M), Version 12.2(55)SE5, RELEASE SOFTWARE (fc1)
ROM: Bootstrap program is C3750E boot loader
BOOTLDR: C3750E Boot Loader (C3750X-HBOOT-M) Version 12.2(58r)SE1, RELEASE SOFTWARE (fc1)
BOS-C3750-SERVER-B uptime is 1 week, 4 days, 19 hours, 58 minutes
System image file is "flash:/c3750e-universalk9-mz.122-55.SE5/c3750e-universalk9-mz.122-55.SE5.bin"
cisco WS-C3750X-48 (PowerPC405) processor (revision A0) with 262144K bytes of memory.
Model number                    : WS-C3750X-48T-S
Version ID                      : V06
Switch Ports Model              SW Version            SW Image
     1 54    WS-C3750X-48       12.2(55)SE5           C3750E-UNIVERSALK9-M
*    2 54    WS-C3750X-48       12.2(55)SE5           C3750E-UNIVERSALK9-M
Model number                    : WS-C3750X-48T-S
Version ID                      : V06

Search for 3750 AND Version per line. So the line must have both 3750 AND Version.

TPA-SWA#show version | include 3750.*Version
Cisco IOS Software, C3750E Software (C3750E-UNIVERSALK9-M), Version 12.2(55)SE5, RELEASE SOFTWARE (fc1)
BOOTLDR: C3750E Boot Loader (C3750X-HBOOT-M) Version 12.2(58r)SE1, RELEASE SOFTWARE (fc1)

As you can see Regular Expressions are powerful and you can do so many things with them.

See the table below from Cisco’s website:

Regular Expression Character

Function

Examples

.

Matches any single character.

0.0 matches 0x0 and 020

t..t matches strings such as test, text, and tart

\

Matches the character following the backslash. Also matches (escapes) special characters.

172\.1\.. matches 172.1.10.10 but not 172.12.0.0

\. allows a period to be matched as a period

[ ]

Matches the characters or a range of characters separated by a hyphen, within left and right square brackets.

[02468a-z] matches 0, 4, and w, but not 1, 9, or K

^

Matches the character or null string at the beginning of an input string.

^123 matches 1234, but not 01234

?

Matches zero or one occurrence of the pattern. (Precede the question mark with Ctrl-V sequence to prevent it from being interpreted as a help command.)

ba?b matches bb and bab

$

Matches the character or null string at the end of an input string.

123$ matches 0123, but not 1234

*

Matches zero or more sequences of the character preceding the asterisk. Also acts as a wildcard for matching any number of characters.

5* matches any occurrence of the number 5 including none

18\..* matches the characters 18. and any characters that follow 18.

+

Matches one or more sequences of the character preceding the plus sign.

8+ requires there to be at least one number 8 in the string to be matched

() []

Nest characters for matching. Separate endpoints of a range with a dash (-).

(17)* matches any number of the two-character string 17

([A-Za-z][0-9])+ matches one or more instances of letter-digit pairs: b8 and W4, as examples

|

Concatenates constructs. Matches one of the characters or character patterns on either side of the vertical bar.

A(B|C)D matches ABD and ACD, but not AD, ABCD, ABBD, or ACCD

_

Replaces a long regular expression list by matching a comma (,), left brace ({), right brace (}), the beginning of the input string, the end of the input string, or a space.

The characters _1300_ can match any of the following strings:

^1300$

^1300space

space1300

{1300,

,1300,

{1300}

,1300,

More Stories
OSPF LSA Types