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!

Index This | Forward, I’m heavy; backward, I’m not. What am I?

April 2024 Edition Hayyy Splunk Education Enthusiasts and the Eternally Curious!  We’re back with another ...

A Guide To Cloud Migration Success

As enterprises’ rapid expansion to the cloud continues, IT leaders are continuously looking for ways to focus ...

Join Us for Splunk University and Get Your Bootcamp Game On!

If you know, you know! Splunk University is the vibe this summer so register today for bootcamps galore ...