Splunk Search

how to extract total count for different fields

wkau
New Member

Hi, i will like to extract the count for the following

Data_no: 1T    
Identity: A  
Data_no: 2T  
Identity: C

i tried the following

| rex max_match= 0 "(?m) Data_no: (?<DataNo>[a-zA-Z0-9#]+)"  
| rex max_match= 0 "(?m) Identity: (?<Identity>[a-zA-Z0-9#]+)"   
| stats count(eval(Identity= "A")) as A, count(eval(Identity= "C")) as C by DataNo

The table returns the following:

DataNO| A | C  
1T    | 1 | 1  
2T    | 1 | 1

How to i filter it so that it will become like this:

DataNO| A | C  
1T    | 1 | 0  
2T    | 0 | 1

Thanks for your help!

0 Karma

somesoni2
Revered Legend

Try this

Updated

your base search| rex max_match= 0 "(?m) Data_no: (?<DataNo>[a-zA-Z0-9#]+)"  
| rex max_match= 0 "(?m) Identity: (?<Identity>[a-zA-Z0-9#]+)" | eval temp=mvzip (DataNo, Identity) | mvexpand temp | rex field=temp "(?<DataNo>.*) (?<Identity>.*)"
| chart count over DataNo by Identity
0 Karma

somesoni2
Revered Legend

Try updated answer.

0 Karma

wkau
New Member

I still got back the same results the data that is provided happens in the same event at the same time, is it possible to filter the DataNO and Identity individually so that it does not double count?

0 Karma

wkau
New Member

after trying that i got A=1, C=1 for 1T and A=1, C=1 for 2T. i will need something like A=1,C=0 for 1T and A=0, C=1 for 2T

0 Karma

strive
Influencer

try this
|chart count by datano identity

0 Karma

wkau
New Member

yup this is an example of how my data is!

0 Karma

strive
Influencer

Data_no: 1T
Identity: A
Data_no: 2T
Identity: C

This is how your data is? If answer is no then can you post some sample log lines.

0 Karma
Got questions? Get answers!

Join the Splunk Community Slack to learn, troubleshoot, and make connections with fellow Splunk practitioners in real time!

Meet up IRL or virtually!

Join Splunk User Groups to connect and learn in-person by region or remotely by topic or industry.

Get Updates on the Splunk Community!

Mastering Threat Intelligence in ES 8.5, Splunk AI Assistant v2, and More from Splunk ...

Splunk Lantern is Splunk’s customer success center that provides practical guidance from Splunk experts on key ...

Break the Build: Inside the KubeDoom Lounge at .conf26

    You step up to the machine. The pixelated corridors of a certain 1993 FPS load in front of you, EMP Pulse ...

Splunk Auto Ingestion Parallel Pipeline Scaling

Why this feature matters Many Splunk environments experience ingestion pressure long before the host is fully ...