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
Super Champion

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!

Get Schooled with Splunk Education: Explore Our Latest Courses

At Splunk Education, we’re dedicated to providing incredible learning experiences that cater to every skill ...

Splunk AI Assistant for SPL | Key Use Cases to Unlock the Power of SPL

Splunk AI Assistant for SPL | Key Use Cases to Unlock the Power of SPL  The Splunk AI Assistant for SPL ...

Buttercup Games: Further Dashboarding Techniques (Part 5)

This series of blogs assumes you have already completed the Splunk Enterprise Search Tutorial as it uses the ...