Splunk Search

Count of values in a multi-value field

hpendela
New Member

Log lines:
k1=doesn't matter, k2=doesn't matter, k3=[v3, v4]
k1=doesn't matter, k2=doesn't matter, k3=[v5, v4, v6]
k1=doesn't matter, k2=doesn't matter, k3=[v5, v6, v9, v4]

Expected output:

v4 => 3
v5 => 2
v6 => 2
v3 => 1
v9 => 1

0 Karma

vnravikumar
Champion

Hi @hpendela

Please try

| makeresults 
| eval log="k1=doesn't matter, k2=doesn't matter, k3=[v3, v4];
k1=doesn't matter, k2=doesn't matter, k3=[v5, v4, v6];
k1=doesn't matter, k2=doesn't matter, k3=[v5, v6, v9, v4]" 
| makemv delim=";" log 
| mvexpand log 
| rex field=log "k3=\[(?P<k3>(.*))]" 
| makemv delim="," k3 
| eval k3= ltrim(k3) 
| stats count by k3
0 Karma

renjith_nair
Legend

@hpendela,

Try

"your base search" | rex field=k3 max_match=0 (?<vals>\w\d+)|stats count by vals

If you have more than one character in v , change the grouping part as (?<vals>\w+\d+)

---
What goes around comes around. If it helps, hit it with Karma 🙂
0 Karma
Get Updates on the Splunk Community!

Detecting Remote Code Executions With the Splunk Threat Research Team

REGISTER NOWRemote code execution (RCE) vulnerabilities pose a significant risk to organizations. If ...

Observability | Use Synthetic Monitoring for Website Metadata Verification

If you are on Splunk Observability Cloud, you may already have Synthetic Monitoringin your observability ...

More Ways To Control Your Costs With Archived Metrics | Register for Tech Talk

Tuesday, May 14, 2024  |  11AM PT / 2PM ET Register to Attend Join us for this Tech Talk and learn how to ...