Splunk Search

How to count after rex multivalue?

kp3343
Engager

Hi,

I am doing rex on a field that looks like this (showing multiple events below)

a#1|b#30|c#6|d#9

b#5|d#7|e#5|f#4

a#6|c#4|e#9

My rex is

 

 

 

rex field=raw max_match=0 "((?<service>[^#]*)#(?<totalRows>[^\|]*)\|?)

 

 

 

 Resulting into

service totalRows
a
b
c
d

1
30
6
9

b
d
e
f
5
7
5
4
a
c
e
6
4
9

 

How can I create a sum of all totalRows for each service ? Basically looking for something that will output like below

service totalRows
a 7
b 35
c 10
d 16
e 14
f 4

 

Labels (2)
0 Karma
1 Solution

ITWhisperer
SplunkTrust
SplunkTrust

Try something like this

| eval row=mvrange(0,mvcount(service))
| mvexpand row
| eval service=mvindex(service, row)
| eval totalRows=mvindex(totalRows, row)
| stats sum(totalRows) as totalRows by service

View solution in original post

0 Karma

ITWhisperer
SplunkTrust
SplunkTrust

Try something like this

| eval row=mvrange(0,mvcount(service))
| mvexpand row
| eval service=mvindex(service, row)
| eval totalRows=mvindex(totalRows, row)
| stats sum(totalRows) as totalRows by service
0 Karma
Get Updates on the Splunk Community!

[Puzzles] Solve, Learn, Repeat: Dynamic formatting from XML events

This challenge was first posted on Slack #puzzles channelFor a previous puzzle, I needed a set of fixed-length ...

Enter the Agentic Era with Splunk AI Assistant for SPL 1.4

  &#x1f680; Your data just got a serious AI upgrade — are you ready? Say hello to the Agentic Era with the ...

Stronger Security with Federated Search for S3, GCP SQL & Australian Threat ...

Splunk Lantern is a Splunk customer success center that provides advice from Splunk experts on valuable data ...