Splunk Search

How to edit my search to return a list within a list?

singhh4
Path Finder

Hey guys,

So what i am trying to do is put a list inside of a list to get an output such as the one below

Comapny    |   Count1  |   Group  |  Count2   |  Environment  |  Count3
_____________________________________________________________________
CompanyID       10        GroupID1      2        Environment1      1
                                                 Environment2      1
                          GroupID2      8        Environment1      4
                                                 Environment2      4
______________________________________________________________________ 
CompanyID2      12        GroupID1      4        Environment1      3
                                                 Environment2      1
                          GroupID2      8        Environment1      2
                                                 Environment2      6

Or this:

Comapny    |   Count1  |   Group  |  Count2   |  Environment1  |   Environment2
_______________________________________________________________________________________
CompanyID       10        GroupID1      2             1                  1
                          GroupID2      8             4                  4
_______________________________________________________________________________________
CompanyID2      12        GroupID1      4             3                  1
                          GroupID2      8             2                  6

I have a search that gets me the Company, Group, and Environment but I can't get the counts and Groups to show up properly

Current search:

index="Customers" |stats count by Customer,Group, Environment |stats sum(count) as Total list(Group) as Source list(count) as Count list(Environment) as Environment list(count) as Count2 by Customer

That search gets me the following output

Comapny    |   Count1  |   Group  |  Count2   |  Environment  |  Count3
_____________________________________________________________________
CompanyID       10        GroupID1               Environment1      1
                          GroupID1               Environment2      1
                          GroupID2               Environment1      4
                          GroupID2               Environment2      4
______________________________________________________________________ 
CompanyID2      12        GroupID1               Environment1      3
                          GroupID1               Environment2      1
                          GroupID2               Environment1      2
                          GroupID2               Environment2      6

How would i get one of the two outputs from above?

Thanks in advanced! 🙂

0 Karma
1 Solution

somesoni2
Revered Legend

Give this a try (for expected format#2)

index="Customers" |stats count by Customer,Group, Environment | eval temp=Customer."#".Group | xyseries temp Environment count
| addtotals fieldname=Count2 | rex field=temp "(?<Customer>[^#]+)#(?<Group>.+)" | fields - temp | stats sum(Count2) as Count1 list(*) as * by Customer

View solution in original post

somesoni2
Revered Legend

Give this a try (for expected format#2)

index="Customers" |stats count by Customer,Group, Environment | eval temp=Customer."#".Group | xyseries temp Environment count
| addtotals fieldname=Count2 | rex field=temp "(?<Customer>[^#]+)#(?<Group>.+)" | fields - temp | stats sum(Count2) as Count1 list(*) as * by Customer

singhh4
Path Finder

You are awesome! Thank you soo much!

0 Karma
Career Survey
First 500 qualified respondents will receive a $20 gift card! Tell us about your professional Splunk journey.
Get Updates on the Splunk Community!

Tech Talk Recap | Mastering Threat Hunting

Mastering Threat HuntingDive into the world of threat hunting, exploring the key differences between ...

Observability for AI Applications: Troubleshooting Latency

If you’re working with proprietary company data, you’re probably going to have a locally hosted LLM or many ...

Splunk AI Assistant for SPL vs. ChatGPT: Which One is Better?

In the age of AI, every tool promises to make our lives easier. From summarizing content to writing code, ...