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!

September Community Champions: A Shoutout to Our Contributors!

As we close the books on another fantastic month, we want to take a moment to celebrate the people who are the ...

Splunk Decoded: Service Maps vs Service Analyzer Tree View vs Flow Maps

It’s Monday morning, and your phone is buzzing with alert escalations – your customer-facing portal is running ...

What’s New in Splunk Observability – September 2025

What's NewWe are excited to announce the latest enhancements to Splunk Observability, designed to help ITOps ...