regexp problem with TCL Script

Answered Question
Jun 15th, 2010

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

I have this problem too.
0 votes
Correct Answer by Joe Clarke about 6 years 5 months ago

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 ]

  • 1
  • 2
  • 3
  • 4
  • 5
Overall Rating: 5 (1 ratings)
Loading.
maintenance.artesys Tue, 06/15/2010 - 07:58

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.

Correct Answer
Joe Clarke Tue, 06/15/2010 - 11:47

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 ]

Actions

This Discussion