Splunk Search

Can I add text to return value of eval/case?

castle1126
Communicator

I'm writing a search that performs a simple eval:

eval changed = case (NOT address="-",address,NOT city="-",city,NOT state="-",state)

One thing I want to do is add some text value to the returned value of the case, based on which boolean worked. For instance, if the address <> "-" I want to return "Address changed to", followed by the value of the field "address", to the new field named "changed".

Is there a way to get the case statement to return that sort of result?

Tags (1)

Ron_Naken
Splunk Employee
Splunk Employee

You can concatenate your strings right in the case statement. Assuming your EVAL expression is correct, you could do it like this to get the address as you wish:

... | eval changed = case(NOT address="-", "Address changed to " + address, NOT city="-", city, NOT state="-", state)

jrodman
Splunk Employee
Splunk Employee

Sounds like you need to build up more complex logic using if() and so on.

0 Karma

castle1126
Communicator

OK. But not knowing too much on the "if" logic, could you add the text as I am looking for? If so could you give me an example?

0 Karma
Get Updates on the Splunk Community!

Enterprise Security Content Update (ESCU) | New Releases

In November, the Splunk Threat Research Team had one release of new security content via the Enterprise ...

Index This | Divide 100 by half. What do you get?

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

Stay Connected: Your Guide to December Tech Talks, Office Hours, and Webinars!

❄️ Celebrate the season with our December lineup of Community Office Hours, Tech Talks, and Webinars! ...