cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
2658
Views
0
Helpful
1
Replies

Regexp in "show" command within TCL script

Jaime Gomez
Level 1
Level 1

I have an EEM applet that executes a show command using regex that works fine. However, when I converted the applet to TCL, I am having some problems with it. It's throwing an error on the line below:

    if [catch {cli_exec $cli1(fd) "sh run | section ip prefix-list [^ ]+ seq 5 permit $ip_prefix\.0\/24"} _cli_result] {

        error $_cli_result $errorInfo

    }

TCL seems to be catching the [^ ] part of the show command and trying a substitution (trying to execute "^ " as a separate command). I could surround the show command with { } brackets but then $ip_prefix won't be substituted for the variable value. Is there any way of executing this show command within TCL? Thanks.

1 Accepted Solution

Accepted Solutions

Dan Frey
Cisco Employee
Cisco Employee

C819G-4G-V-K9#tclsh

C819G-4G-V-K9(tcl)#set ip_prefix 10.10.10

10.10.10

C819G-4G-V-K9(tcl)#sh run | section ip prefix-list [^ ]+ seq 5 permit $ip_prefix\.0\/24

invalid command name "^"                   ^

% Invalid input detected at '^' marker.

This works:

C819G-4G-V-K9(tcl)#sh run | section ip prefix-list \[\^ \]+ seq 5 permit $ip_prefix\.0\/24

ip prefix-list test seq 5 permit 10.10.10.0/24

View solution in original post

1 Reply 1

Dan Frey
Cisco Employee
Cisco Employee

C819G-4G-V-K9#tclsh

C819G-4G-V-K9(tcl)#set ip_prefix 10.10.10

10.10.10

C819G-4G-V-K9(tcl)#sh run | section ip prefix-list [^ ]+ seq 5 permit $ip_prefix\.0\/24

invalid command name "^"                   ^

% Invalid input detected at '^' marker.

This works:

C819G-4G-V-K9(tcl)#sh run | section ip prefix-list \[\^ \]+ seq 5 permit $ip_prefix\.0\/24

ip prefix-list test seq 5 permit 10.10.10.0/24

Getting Started

Find answers to your questions by entering keywords or phrases in the Search bar above. New here? Use these resources to familiarize yourself with the community: