Splunk Search

Combine values from mutliple rows

magriii
Explorer

Goal is to subtract file counts of folders from sites MAIN and BACK.

Sample data

 

| makeresults
| eval f="MAIN-AAA", val="17313"
| append [| makeresults | eval f="BACK-AAA", val="17357"]
| append [| makeresults | eval f="MAIN-BBB", val="682"]
| append [| makeresults | eval f="BACK-BBB", val="682"]
| append [| makeresults | eval f="MAIN-CCC", val="38767"]
| append [| makeresults | eval f="BACK-CCC", val="38804"]
| eval site=substr(f,1,4) | eval folder=substr(f,6)

 

Output should be something like

 

folder,count MAIN,count BACK,difference
AAA,17313,17357,4
BBB,682,682,0
CCC,38804,38767,37

 

thanks

Labels (1)
0 Karma
1 Solution

ITWhisperer
SplunkTrust
SplunkTrust
| eval countMAIN=if(site="MAIN",val,NULL())
| eval countBACK=if(site="BACK",val,NULL())
| fields countMAIN, countBACK, folder
| stats values(*) as * by folder
| eval difference=abs(countMAIN-countBACK)

View solution in original post

ITWhisperer
SplunkTrust
SplunkTrust
| eval countMAIN=if(site="MAIN",val,NULL())
| eval countBACK=if(site="BACK",val,NULL())
| fields countMAIN, countBACK, folder
| stats values(*) as * by folder
| eval difference=abs(countMAIN-countBACK)
Get Updates on the Splunk Community!

Introducing the Splunk Community Dashboard Challenge!

Welcome to Splunk Community Dashboard Challenge! This is your chance to showcase your skills in creating ...

Built-in Service Level Objectives Management to Bridge the Gap Between Service & ...

Wednesday, May 29, 2024  |  11AM PST / 2PM ESTRegister now and join us to learn more about how you can ...

Get Your Exclusive Splunk Certified Cybersecurity Defense Engineer Certification at ...

We’re excited to announce a new Splunk certification exam being released at .conf24! If you’re headed to Vegas ...