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!

.conf24 | Registration Open!

Hello, hello! I come bearing good news: Registration for .conf24 is now open!   conf is Splunk’s rad annual ...

ICYMI - Check out the latest releases of Splunk Edge Processor

Splunk is pleased to announce the latest enhancements to Splunk Edge Processor.  HEC Receiver authorization ...

Introducing the 2024 SplunkTrust!

Hello, Splunk Community! We are beyond thrilled to announce our newest group of SplunkTrust members!  The ...