Splunk Search

How to use AND in an eval case function?

ibekacyril
Explorer

I need a way of using AND in the eval function case.

For Example:

...mysearch | eval Path = case(Path=="my/path" AND Action=="check", "Yours is available", Path=="your/path" AND Action=="didnotcheck", "Mine is available" )

This did not work for me, so it seems I am doing something wrong. Thanks in advance

Tags (3)
0 Karma

javiergn
SplunkTrust
SplunkTrust

Maybe your path contains special characters, try using match and just specifying part of your path to see if that works. If that's the case then try replacing the match with the "==" and escaping the special characters with a backslash. I would also include a default condition (1==1) in case none of the others match and also create a variable with a different name (like NewPath) to avoid overwriting your Path variable while you are still testing this and in order to see what's going on:

mysearch 
| eval NewPath = case(
    match(Path,"my path") AND Action=="check", "Yours is available",
    match(Path,"your path") AND Action=="didnotcheck", "Mine is available" 
    1 == 1, "Others"
)
0 Karma

HiroshiSatoh
Champion

How to use the AND is not wrong. Please tell me the contents of the mistake of the search results.

< search results>
Path=="my/path" AND Action=="check" : Path="Yours is available"
Path=="your/path" AND Action=="didnotcheck" : Path="Mine is available"
else :Path=NULL

Do you have field names and path match? For example,
"... Mysearch | dedup Path, Action"
What a result of?

0 Karma

ibekacyril
Explorer

I would like to capture this cases in a field so that I can pipe it to stats. That's why I used case and eval

0 Karma
Get Updates on the Splunk Community!

Index This | I am a number, but when you add ‘G’ to me, I go away. What number am I?

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

What’s New in Splunk App for PCI Compliance 5.3.1?

The Splunk App for PCI Compliance allows customers to extend the power of their existing Splunk solution with ...

Extending Observability Content to Splunk Cloud

Register to join us !   In this Extending Observability Content to Splunk Cloud Tech Talk, you'll see how to ...