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!

Upcoming Webinar: Unmasking Insider Threats with Slunk Enterprise Security’s UEBA

Join us on Wed, Dec 10. at 10AM PST / 1PM EST for a live webinar and demo with Splunk experts! Discover how ...

.conf25 technical session recap of Observability for Gen AI: Monitoring LLM ...

If you’re unfamiliar, .conf is Splunk’s premier event where the Splunk community, customers, partners, and ...

A Season of Skills: New Splunk Courses to Light Up Your Learning Journey

There’s something special about this time of year—maybe it’s the glow of the holidays, maybe it’s the ...