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!

Updated Team Landing Page in Splunk Observability

We’re making some changes to the team landing page in Splunk Observability, based on your feedback. The ...

New! Splunk Observability Search Enhancements for Splunk APM Services/Traces and ...

Regardless of where you are in Splunk Observability, you can search for relevant APM targets including service ...

Webinar Recap | Revolutionizing IT Operations: The Transformative Power of AI and ML ...

The Transformative Power of AI and ML in Enhancing Observability   In the realm of IT operations, the ...