Networking 使用tcl中的接口名称从sh ip int简要说明中提取ip地址
我是TCL的新手,我尝试使用接口名提取特定接口的ip地址 样本输入:Networking 使用tcl中的接口名称从sh ip int简要说明中提取ip地址,networking,tcl,expect,Networking,Tcl,Expect,我是TCL的新手,我尝试使用接口名提取特定接口的ip地址 样本输入: Interface IP-Address OK? Method Status Protocol Embedded-Service-Engine0/0 unassigned YES NVRAM administratively down down GigabitEthernet0/0 unassigned YE
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
我试过这个
regexp -line ^ $interfacename.*?(?=(?:\\..*?)?\\d{1,}) $temp
但它没有给我任何答案。。。。有人能帮我吗。您正在尝试提取IP地址?例如,对于千兆以太网/1,您需要192.168.2.1,对吗 如果是:
% 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
在这里,你不需要向前看。此外,您不希望在“^”字符后有空格