Getting Data In

Count values delimited by "," in a field

habrhi
Explorer

Hi guys,

I have the following exemple:
Searching the "s" in Field B delimited by "," , my expected result is the following
FIELD A | FIELD B | COUNT
x | s,a,b,c | 1
y | s,x,x,xs | 2
z | s,a,s,s,s | 4

Thanks for the help

0 Karma
1 Solution

manjunathmeti
Champion

Use rex to extract character 's' and count it.

| rex field=_raw max_match=0 "(?[s]+)" | eval slen=mvcount(smatch)

Sample query:

| makeresults | eval "FIELD A"="x", "FIELD B"="s,a,b,c" | append [| makeresults | eval "FIELD A"="y", "FIELD B"="s,x,x,xs"] | append [| makeresults | eval "FIELD A"="z", "FIELD B"="s,a,s,s,s"] | rex field="FIELD B" max_match=0 "(?<smatch>[s]+)" | eval count=mvcount(smatch) | table "FIELD A", "FIELD B", count

View solution in original post

habrhi
Explorer

thanks , that was clear .
regards

0 Karma

Vijeta
Influencer

@habrhi - assuming A and B are your field names

your query |eval newB=B| makemv delim="," newB| mvexpand newB| stats count(eval(LIKE(newB,"%s%"))) as c by A B

manjunathmeti
Champion

Use rex to extract character 's' and count it.

| rex field=_raw max_match=0 "(?[s]+)" | eval slen=mvcount(smatch)

Sample query:

| makeresults | eval "FIELD A"="x", "FIELD B"="s,a,b,c" | append [| makeresults | eval "FIELD A"="y", "FIELD B"="s,x,x,xs"] | append [| makeresults | eval "FIELD A"="z", "FIELD B"="s,a,s,s,s"] | rex field="FIELD B" max_match=0 "(?<smatch>[s]+)" | eval count=mvcount(smatch) | table "FIELD A", "FIELD B", count
Get Updates on the Splunk Community!

Introducing the 2024 SplunkTrust!

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

Introducing the 2024 Splunk MVPs!

We are excited to announce the 2024 cohort of the Splunk MVP program. Splunk MVPs are passionate members of ...

Splunk Custom Visualizations App End of Life

The Splunk Custom Visualizations apps End of Life for SimpleXML will reach end of support on Dec 21, 2024, ...