Splunk Search

Is it possible to extract results of an eval match as fields?

ibekacyril
Explorer

Is it possible to do something like this:

...|eval Classification=case(match(class,"Boy"),"Boy",match(class,"Girl"),"Girl",match(class,"Man"),"Man") |code_I_am_looking_for | stats count by Boy,Girl,Man

Thanks in advance

0 Karma
1 Solution

javiergn
Super Champion

Have you tried with chart?

| eval Classification=case(match(class,"Boy"),"Boy",match(class,"Girl"),"Girl",match(class,"Man"),"Man")
| chart count over class by Classification
| fields - class

Alternatively, if you you know the name of your fields in advanced you could also do:

| eval Classification=case(match(class,"Boy"),"Boy",match(class,"Girl"),"Girl",match(class,"Man"),"Man")
| eval Boy = if (Classification == "Boy", 1, 0)
| eval Girl = if (Classification == "Girl", 1, 0)
| eval Man = if (Classification == "Man", 1, 0)
| stats sum(*) as *

View solution in original post

javiergn
Super Champion

Hi, did any of the comments below help you on this?
If yes, can you mark it as answered?
If not, is there any else we can do to help?
Unanswered questions make me sad 😞

0 Karma

ibekacyril
Explorer

Hi Javiergn, sorry about the late response, your answer was very helpful

0 Karma

Richfez
SplunkTrust
SplunkTrust

From your response to my other Answer, maybe this answer will suit your need better.

... | stats count(eval(match(class, "Boy"))) AS "Boy" count(eval(match(class, "Girl"))) AS "Girl" count(eval(match(class, "Man"))) AS "Man"

That gets rid of a lot of complexity but should end up with an output like your description "I want to split the match into fields if possible, then do stats count on the new fields"

Give that a try and let us know!

0 Karma

javiergn
Super Champion

Have you tried with chart?

| eval Classification=case(match(class,"Boy"),"Boy",match(class,"Girl"),"Girl",match(class,"Man"),"Man")
| chart count over class by Classification
| fields - class

Alternatively, if you you know the name of your fields in advanced you could also do:

| eval Classification=case(match(class,"Boy"),"Boy",match(class,"Girl"),"Girl",match(class,"Man"),"Man")
| eval Boy = if (Classification == "Boy", 1, 0)
| eval Girl = if (Classification == "Girl", 1, 0)
| eval Man = if (Classification == "Man", 1, 0)
| stats sum(*) as *

Richfez
SplunkTrust
SplunkTrust

Have you tried just

...|eval Classification=case(match(class,"Boy"),"Boy",match(class,"Girl"),"Girl",match(class,"Man"),"Man")  | stats count by Classification

?

0 Karma

ibekacyril
Explorer

No, that's not what I want. Doing a stat count by classification lists Boy,Girl,Man under Classification. I want to split the match into fields if possible, then do stats count on the new fields

0 Karma
Get Updates on the Splunk Community!

Splunk Observability for AI

Don’t miss out on an exciting Tech Talk on Splunk Observability for AI!Discover how Splunk’s agentic AI ...

Splunk Enterprise Security 8.x: The Essential Upgrade for Threat Detection, ...

Watch On Demand the Tech Talk on November 6 at 11AM PT, and empower your SOC to reach new heights! Duration: ...

Splunk Observability as Code: From Zero to Dashboard

For the details on what Self-Service Observability and Observability as Code is, we have some awesome content ...