Splunk Search

How to extract the last three digits after the ">" sign, and than the summation of those values?

amaralt808
Path Finder

Hello,

I have a search that prints out a list of numbers in this format.

[144 ==> 143]
[145 ==> 144]
[144 ==> 145]
[145 ==> 144]
[144 ==> 145]
[143 ==> 144]
[144 ==> 143]
[143 ==> 144]
[144 ==> 143]
[143 ==> 144]
[142 ==> 143]
[143 ==> 142]
[144 ==> 143]

I want to extract the last three digits after the ">" sign.

For example, [144 ==> 143] turns into 143.

Then I want a summation of those values, so I guess I need to turn it into an int.

Here is what I have so far
rex "==>(?<regexusers>.*)"

Where regexusers is what is being saved.

Any help will be greatly appreciated!!

Labels (2)
0 Karma
1 Solution

ITWhisperer
SplunkTrust
SplunkTrust
| rex "==>.+?(?<regexusers>\d{1,3})\]"

View solution in original post

0 Karma

somesoni2
Revered Legend

Try something like this

Your current search giving those numbers/text
[144 ==> 143]
| rex field=YourfieldNameHere "\>\s*(?<regexusers>\d+)"
| stats sum(regexusers) as regexusers
0 Karma

ITWhisperer
SplunkTrust
SplunkTrust
| rex "==>.+?(?<regexusers>\d{1,3})\]"
0 Karma

amaralt808
Path Finder

I hate to ask, but could you explain the process?

| rex "==>.+?(?<regexusers>\d{1,3})\]"

rex -> Look for "==>"  

.+ -> Followed by any new character except end line. 
what does ?(? mean

<regexusers> = group i want to save it to

\d{1,3} = any digit that are 1-3 characters. 

} end group

what does \ mean?

Tags (1)
0 Karma

ITWhisperer
SplunkTrust
SplunkTrust

You can use regex101.com to explain regex

https://regex101.com/r/hlErAZ/1 

But to answer the questions specifically, the ? reduces the unlimited + to as few characters as possible to still fit the rest of the pattern.

The \] is to anchor the pattern at the end of the digits. I used \] as ] is sometimes used as a special character, although, to be fair, in this instance, the \ isn't strictly necessary.

0 Karma

somesoni2
Revered Legend

Regex uses backslash ( \ ) for two purposes: 1) for metacharacters such as \d (digit), \D (non-digit), \s (space), \S (non-space), \w (word), \W (non-word). 2) to escape special regex characters, e.g., \. OR \+

0 Karma

amaralt808
Path Finder

I love you.

It worked!

0 Karma
Get Updates on the Splunk Community!

CX Day is Coming!

Customer Experience (CX) Day is on October 7th!! We're so excited to bring back another day full of wonderful ...

Strengthen Your Future: A Look Back at Splunk 10 Innovations and .conf25 Highlights!

The Big One: Splunk 10 is Here!  The moment many of you have been waiting for has arrived! We are thrilled to ...

Now Offering the AI Assistant Usage Dashboard in Cloud Monitoring Console

Today, we’re excited to announce the release of a brand new AI assistant usage dashboard in Cloud Monitoring ...