cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
1568
Views
0
Helpful
2
Replies

Best EEM practice for extracting a line from show command

pingduck
Level 1
Level 1

I am trying to write an EEM script to extract a line from the output of a show command.

What is the regexp pattern that can help me extract the first line of output? (til the first "\n"). I tried many regexp patterns to no avail.

 

 

Just FYI, I ended up with a for loop. It works but not very elegant:

 

event manager applet test

event none

action 1 cli command "enable"

action 2 cli command "show run | i ip route 1.2.3.4"

action 3 foreach line "$_cli_result" "\n"

action 4  break

action 5 end

action 6 puts "$line"

 

also, the $line variable contains the "\n" in the end. I would match prefer using string match or regexp action to extract output with 1 line.

2 Replies 2

pingduck
Level 1
Level 1

answering my own question, 

 

action 3 regexp "^ip route[^\n]*" "$_cli_result" match

Looks like the solution is not the best, when there are more than 1 match. The $match will contain a trailing "\n". But if there is only 1 match, the $match will not contain a trailing "\n".