Splunk Search

How to create a calculated field eval coalesce follow by case statement?


I'm trying to create a calculated field (eval) that will coalesce a bunch of username fields, then perform match() and replace() functions within a case statement.

Here's a scenario:

  • Possible user fields: UserName, username, User_ID
  • User values need domain removed (e.g., "user@domain.com" or "ad\user" needs to be "user").

Here is how it can be done in two evals (I newlined and indented each case for readability):


| eval user_coalesced = coalesce(UserName, username, User_ID)
| eval user = case(
  match(user_coalesced, ".*@.*"), replace(user_coalesced, "@.*", ""),
  match(user_coalesced, "^ad\\\\"), replace(user_coalesced, "^ad\\\\", ""),
  true(), user


 Any ideas on how I can get this down to one? I thought about putting the coalesce() into each case, but that seems inefficient.

Labels (1)
Tags (2)
0 Karma
Get Updates on the Splunk Community!

Splunk Forwarders and Forced Time Based Load Balancing

Splunk customers use universal forwarders to collect and send data to Splunk. A universal forwarder can send ...

NEW! Log Views in Splunk Observability Dashboards Gives Context From a Single Page

Today, Splunk Observability releases log views, a new feature for users to add their logs data from Splunk Log ...

Last Chance to Submit Your Paper For BSides Splunk - Deadline is August 12th!

Hello everyone! Don't wait to submit - The deadline is August 12th! We have truly missed the community so ...