Splunk Search

How would I use eval with a wildcard to create a combined value?

the_wolverine
Champion

I have many email addresses that I want to lump by domain. How do I use eval to do this?

1 Solution

the_wolverine
Champion

index=main sourcetype=email address=* | eval domain=case(address LIKE "%gmail.com", "GMAIL", address LIKE "%yahoo.com", "YAHOO",address LIKE "%hotmail.com","HOTMAIL") | stats count by domain

(% is the wildcard)

There are many ways to do this so I hope other folks add their examples.

View solution in original post

mikaelbje
Motivator

For completeness here's another way to achieve this:

index=* address=* | eval x=split(address, "@") | eval domain=mvindex(x,1)

Not sure which solution is faster though

sk314
Builder

You could also use rex on your email address field to capture domain in a separate field. This way you do not have to list out all possible domain cases in an eval statement.

For example:

index=<your index> sourcetype=<your sourcetype> | rex field=<email_address_field> "\w+@(?<domain>\w+)\.\w+" | ... 

This captures your domains in a separate field (domain). Hope this helps.

the_wolverine
Champion

index=main sourcetype=email address=* | eval domain=case(address LIKE "%gmail.com", "GMAIL", address LIKE "%yahoo.com", "YAHOO",address LIKE "%hotmail.com","HOTMAIL") | stats count by domain

(% is the wildcard)

There are many ways to do this so I hope other folks add their examples.

Get Updates on the Splunk Community!

Threat Hunting Unlocked: How to Uplevel Your Threat Hunting With the PEAK Framework ...

WATCH NOWAs AI starts tackling low level alerts, it's more critical than ever to uplevel your threat hunting ...

Splunk APM: New Product Features + Community Office Hours Recap!

Howdy Splunk Community! Over the past few months, we’ve had a lot going on in the world of Splunk Application ...

Index This | Forward, I’m heavy; backward, I’m not. What am I?

April 2024 Edition Hayyy Splunk Education Enthusiasts and the Eternally Curious!  We’re back with another ...