Reputation: 3
I am new to TCL and Expect.I tried to extract ip address of a particular interface using the interface name.
sample input:
Interface IP-Address OK? Method Status Protocol
Embedded-Service-Engine0/0 unassigned YES NVRAM administratively down down
GigabitEthernet0/0 unassigned YES NVRAM up up
GigabitEthernet0/0.10 10.1.1.1 YES NVRAM up up
GigabitEthernet0/0.20 20.1.1.2 YES NVRAM up up
GigabitEthernet0/1 192.168.2.1 YES NVRAM up up
GigabitEthernet0/2 192.168.1.1 YES NVRAM up up
I tried this,
regexp -line ^ $interfacename.*?(?=(?:\\..*?)?\\d{1,}) $temp
but its not giving me any answers.... Can somebody help me in this.
Upvotes: 0
Views: 307
Reputation: 247062
You are trying to extract the IP address? Example, for "GigabitEthernet/1" you want 192.168.2.1, correct?
If yes:
% set interfacename GigabitEthernet0/1
GigabitEthernet0/1
% set re "^$interfacename\\s+(\[\\d.]+)"
^GigabitEthernet0/1\s+([\d.]+)
% regexp -inline -line $re $input
{GigabitEthernet0/1 192.168.2.1} 192.168.2.1
% regexp -line $re $input -> ip
1
% set ip
192.168.2.1
You don't need a lookahead here. Also, you don't want a space after the ^
character.
Upvotes: 1