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. If you'd prefer to explore, try our test area to get started. And see here for current known issues.

Cisco Employee

How to select part of a string?

Hi,

I have the following string from a cli command output:

630860 packets input, 624821204 bytes, 0 no buffer

I want to select the number of bytes which is of a variable length. Is there a way to do this with the action string commands? I couldn't get this to work for me.

Kind regards,

Ryan

  • EEM Scripting
1 ACCEPTED SOLUTION

Accepted Solutions
Cisco Employee

How to select part of a string?

Use regexp:

regexp "([0-9]+) bytes" $string match bytes

puts "Bytes is $bytes"

3 REPLIES
Cisco Employee

How to select part of a string?

Use regexp:

regexp "([0-9]+) bytes" $string match bytes

puts "Bytes is $bytes"

Cisco Employee

How to select part of a string?

Ok this works.

What do the ( ) brackets indicate? I had tried a similar string in the past but I didn't have these brackets.

Ryan

Cisco Employee

How to select part of a string?

They indicate that you want to extract a sub-match, in this case the number of bytes.

382
Views
0
Helpful
3
Replies
This widget could not be displayed.