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!

Observability Unlocked: Kubernetes Monitoring with Splunk Observability Cloud

  Ready to master Kubernetes and cloud monitoring like the pros?Join Splunk’s Growth Engineering team for an ...

Wrapping Up Cybersecurity Awareness Month

October might be wrapping up, but for Splunk Education, cybersecurity awareness never goes out of season. ...

🌟 From Audit Chaos to Clarity: Welcoming Audit Trail v2

🗣 You Spoke, We Listened  Audit Trail v2 wasn’t written in isolation—it was shaped by your voices.  In ...