Cisco Support Community
cancel
Showing results for 
Search instead for 
Did you mean: 
Announcements

Welcome to Cisco Support Community. We would love to have your feedback.

For an introduction to the new site, click here. And see here for current known issues.

regexp problem with TCL Script

Hello,

I'm having some troubles with my regexp in a tcl script.

My switch 3750 doesn't want to compil my script if there is [0-9] or \d in my script ...

After a show energywise children I'm doing:

set intd [ regexp -all -line -inline "1\/0\/." $result ]

($result is the show energywise cli result)

It work with interfaces from 1/0/1to9.

set intd [ regexp -all -line -inline "1\/0\/.." $result ]

It work with interfaces from 1/0/10to48

but i need to have all interfaces in the same regexp, why "1\/0\/[0-9]+" or "1\/0\/\d+" don't work ?

Here is my ios : c3750-ipservicesk9-mz.122-53.SE1.bin

Anybody have a clue ?

Thanks

1 ACCEPTED SOLUTION

Accepted Solutions
Cisco Employee

Re: regexp problem with TCL Script

Replace the "" with {}.  That is, you need to escape the '[' if you want to use it, or include it in literal "{}".  For example:

set intd [ regexp -all -line -inline {1\/0\/[0-9]+.} $result ]

3 REPLIES

Re: regexp problem with TCL Script

Maybe need more details, my eem version is :

Embedded Event Manager Version 3.20                                           
Component Versions:                                                           
eem: (v320_throttle)2.1.50                                                    
eem-gold: (v320_throttle)1.0.4                                                
eem-call-home: (v320_throttle)1.0.4                                           
Event Detectors:                                                              
Name                Version   Node        Type                                
application         01.00     node0/0     RP                                  
mat                 01.00     node0/0     RP                                  
neighbor-discovery  01.00     node0/0     RP                                  
identity            01.00     node0/0     RP                                  
syslog              01.00     node0/0     RP                                  
routing             03.00     node0/0     RP                                  
cli                 01.00     node0/0     RP                                  
counter             01.00     node0/0     RP
interface           01.00     node0/0     RP
ioswdsysmon         01.00     node0/0     RP
none                01.00     node0/0     RP
oir                 01.00     node0/0     RP
snmp                01.00     node0/0     RP
snmp-object         01.00     node0/0     RP
ipsla               01.00     node0/0     RP
snmp-notification   01.00     node0/0     RP
timer               01.00     node0/0     RP
rpc                 01.00     node0/0     RP

My problem is here :

if [catch {cli_exec $cli(fd) "show ene chi | include SEP"} result] {
    error $result $errorInfo
}
    puts "$result"

foreach intf [ regexp -all -line -inline "00.{10}" $result ] {   /* this line is good, it save the mac address of an equipment*/
  set intd [ regexp -all -line -inline "1\/0\/.." $result ]
  puts "Mac-address:$intf"
  puts "test:$intd"
  }

So my code works but the regexp "1\/0\/.." give me the interface from 1/0/1 to 9 betwin { }.

If i try "1\/0\/[0-9]+" or "1\/0\/\d+", it returns nothing, and I have an error at compilation.

Cisco Employee

Re: regexp problem with TCL Script

Replace the "" with {}.  That is, you need to escape the '[' if you want to use it, or include it in literal "{}".  For example:

set intd [ regexp -all -line -inline {1\/0\/[0-9]+.} $result ]

Re: regexp problem with TCL Script

Thank you, my problem is solved. I didn't know for the { }, it's perfect.

1232
Views
0
Helpful
3
Replies