Reply
Accepted Solution

Match a string between double quotes in CCS

[ Edited ]
Authority
Posts: 20
2633     0

I need to get the output of a string that the Cisco show command outputs between double quotes on some platforms and without quotes on other platforms.  The command is the show key chain command.  The NX-OS platform that outputs with no quotes is easy but the IOS that does output with the quotes I cannot seem to get the variable to extract without including the quotes in CCS. The key can have lots of characters including white spaces, what I am trying to capture is the string p@ssword123! without the double quotes and put that value into a string variable.

 

Key-chain mykey:
    key 1 -- text "p@ssword123!"
        accept lifetime (always valid) - (always valid) [valid now]
        send lifetime (always valid) - (always valid) [valid now]

Re: Match a string between double quotes in CCS

Expert
Posts: 259
2633     0

I haven't tested this but here's one way approach it -- capture the entire string including white spaces and then strip any quotes.

 

Trigger-Variables:

   $key   string

Trigger-Template:

   key 1 -- text [[$key]]

 

Trigger-Commands:

   SET: $mykey =~ s/\"//g

 

This may prove problematic as you attempt to utilize the result in any operations that perform the substitution, if there are space characters or other special characters.

Re: Match a string between double quotes in CCS

Expert
Posts: 259
2633     0

Also, if you're not already familiar with it, the regular expression tester is a much faster way to prototype:

 

http://netmriIP/netmri/ccs/tx/regex_test/index.tdf

Highlighted

Re: Match a string between double quotes in CCS

Authority
Posts: 20
2633     0

I got it to work I have not ran into any spaces of special characters to determine if this fix failes those conditions.  What I had to do was this:

 

Trigger-Variables:

   $key   string

Trigger-Template:

   key 1 -- text [[$key]]

 

Trigger-Commands: { $key no "null" }

   SET: $key =~ s/\"//g

   SET: $newkey = $key

 

Trigger-Commands: { $newkey no "null" }

  DEBUG: $name , $ipaddress , $newkey

 

Showing results for 
Search instead for 
Do you mean 

Recommended for You