Sie sind auf Seite 1von 10

Regular Expression and

Show Commands

Regular
egular Expressions Overview

A regular expression is a pattern (for example a


phrase or a number) that can be used very
effectively to filter output. Regular expressions are
case-sensitive and allow for complex matching
requirements.
Regular expressions are used in many places in the
IOS including BGP AS paths and Voice number
translations. They are also used in other languages
like Perl and TCL.
Regular expressions are used also with IOS show
commands.

egular Expressions- The problem CHALLENGE 1

There is a router with 2.000 routes and I want


to see the routes that have 10 on their first
octet.
I issue the comand:
show ip route | i 10.
but, with this commands these kind of routes
match
10.0.1.0
100.1.0.0
200.10.0.0
1.101.0.0
192.168.1.10

^ Regular Expression
Use this to look for text at the beginning of a string.
Without regular expression

With regular expression

Router#show run | include ip


ip cef
no ip dhcp use vrf connected
ip dhcp pool ITS
option 150 ip 10.1.1.1
no ip domain lookup
voice service voip
allow-connections h323 to sip
allow-connections sip to h323
allow-connections sip to sip
ip address 192.168.10.1 255.255.255.0
ip address 192.168.11.1 255.255.255.0
ip address 192.168.12.1 255.255.255.0
ip address 192.168.13.1 255.255.255.0
ip address 192.168.14.1 255.255.255.0
<MORE>

Router#show run | include ^ip


ip cef
ip dhcp pool ITS
ip http server

$ Regular Expression
Use this to look for text at the end of a string.
Without regular expression

With regular expression

Router#show run | include 1


Current configuration : 5174 bytes
! Last configuration change at 15:27:21
UTC Wed Jan 24 2007
! NVRAM config last updated at 14:25:01
UTC Wed Jan 24 2007
version 12.4
network 10.1.1.0 255.255.255.0
option 150 ip 10.1.1.1
default-router 10.1.1.1
source-address 10.1.1.1 port 5060
create profile sync 0002381328447096
voice register dn 1
number 1100
number 1101
voice register pool 1
id mac 0003.6B8B.174A
number 1 dn 1
codec g711ulaw
ip address 192.168.10.1 255.255.255.0
interface Loopback1
ip address 192.168.11.1 255.255.255.0
ip address 192.168.12.1 255.255.255.0
ip address 192.168.13.1 255.255.255.0

Router#show run | include 1$


The output is:
Router#show run | include 1$
voice register dn 1
number 1101
voice register pool 1
number 1 dn 1
interface Loopback1
interface Loopback11
interface Loopback21
interface FastEthernet0/1
session target ipv4:10.1.1.1
session target ipv4:10.1.1.11
session target ipv4:10.1.1.21
session target ipv4:10.1.1.31
session target ipv4:10.1.1.41
session target ipv4:10.1.1.51
session target ipv4:10.1.1.61
number 1001
ephone 1
button 1:1

_ Regular Expression
This 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.
Without regular expression
Router#show ip route | include k2
C 192.168.12.0/24 is directly
C 192.168.31.0/24 is directly
C 192.168.30.0/24 is directly
C 192.168.32.0/24 is directly

connected,
connected,
connected,
connected,

Loopback2
Loopback21
Loopback20
Loopback22

With regular expression


Router#show ip route | include k2_
C 192.168.12.0/24 is directly connected, Loopback2

[ ] Regular Expression
This matches the characters or a range of characters separated by a hyphen, within left
and right square brackets.
Without regular expression

Router#show ip route | include


C 192.168.12.0/24 is directly
C 192.168.29.0/24 is directly
C 192.168.28.0/24 is directly
C 192.168.13.0/24 is directly
C 192.168.14.0/24 is directly
C 192.168.31.0/24 is directly
C 192.168.30.0/24 is directly
C 192.168.15.0/24 is directly
C 192.168.25.0/24 is directly
C 192.168.24.0/24 is directly
C 192.168.27.0/24 is directly
C 192.168.26.0/24 is directly
C 192.168.11.0/24 is directly
C 192.168.21.0/24 is directly
C 192.168.20.0/24 is directly
C 192.168.23.0/24 is directly
C 192.168.22.0/24 is directly
C 192.168.17.0/24 is directly
C 192.168.16.0/24 is directly
C 192.168.19.0/24 is directly
C 192.168.32.0/24 is directly
C 192.168.18.0/24 is directly

k
connected,
connected,
connected,
connected,
connected,
connected,
connected,
connected,
connected,
connected,
connected,
connected,
connected,
connected,
connected,
connected,
connected,
connected,
connected,
connected,
connected,
connected,

With regular expression

Loopback2
Loopback19
Loopback18
Loopback3
Loopback4
Loopback21
Loopback20
Loopback5
Loopback15
Loopback14
Loopback17
Loopback16
Loopback1
Loopback11
Loopback10
Loopback13
Loopback12
Loopback7
Loopback6
Loopback9
Loopback22
Loopback8

Router#show ip route
C 192.168.12.0/24 is
C 192.168.13.0/24 is
C 192.168.14.0/24 is
C 192.168.15.0/24 is
C 192.168.11.0/24 is
C 192.168.17.0/24 is
C 192.168.16.0/24 is
C 192.168.19.0/24 is
C 192.168.18.0/24 is

| include k[1-9]_
directly connected,
directly connected,
directly connected,
directly connected,
directly connected,
directly connected,
directly connected,
directly connected,
directly connected,

Loopback2
Loopback3
Loopback4
Loopback5
Loopback1
Loopback7
Loopback6
Loopback9
Loopback8

\ Regular Expression
Use this if the following character is not a wildcard, but
an actual character you are looking for.
Without regular expression

With regular expression

Router#show running-con | include 10..

Router#show running-con | include 10\.\.

network 10.1.1.0 255.255.255.0


option 150 ip 10.1.1.1
default-router 10.1.1.1
source-address 10.1.1.1 port 5060
ip address 10.1.1.1 255.255.255.0
destination-pattern 10..
session target ipv4:10.1.1.1
session target ipv4:10.1.1.6
session target ipv4:10.1.1.11
session target ipv4:10.1.1.16
session target ipv4:10.1.1.21
session target ipv4:10.1.1.26
session target ipv4:10.1.1.31
session target ipv4:10.1.1.36
session target ipv4:10.1.1.41
dial-peer voice 10 voip
session target ipv4:10.1.1.46
session target ipv4:10.1.1.51
session target ipv4:10.1.1.56
session target ipv4:10.1.1.61
session target ipv4:10.1.1.66
registrar ipv4:10.1.1.1 expires 60
load 7910 P00405000700
--More--

destination-pattern 10..

+ Regular Expression
This matches one or more sequences of the character
preceding the plus sign.
With regular expression
Router#sh run | i 00+
load 7960-7940 P0S3-07-4-00
create profile sync 0002381328447097
number 1100
id mac 0003.6B8B.174A
clock rate 2000000
tftp-server flash:P0S3-07-4-00.bin
tftp-server flash:P003-07-4-00.bin
tftp-server flash:P0S3-07-4-00.loads
tftp-server flash:P003-07-4-00.sbn
tftp-server flash:P0S3-07-4-00.sb2
tftp-server flash:P00405000700.bin
tftp-server flash:P00405000700.sbn
tftp-server flash:P0030702T023.bin
tftp-server flash:P0030702T023.loads
tftp-server flash:P0030702T023.sb2
tftp-server flash:P0030702T023.sbn
load 7910 P00405000700
load 7960-7940 P0030702T023
ip source-address 10.1.1.1 port 2000
number 1000
number 1001

Regular Expressions- The answer


There is a router with 2.000 routes and I want
to see the routes that have 10 on their first
octet.
I issue the comand:
show ip route | i 10.
but, with this commands these kind of routes
match
10.0.1.0
100.1.0.0
200.10.0.0
1.101.0.0
192.168.1.10
What command could I use?

Das könnte Ihnen auch gefallen