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!

Splunk Custom Visualizations App End of Life

The Splunk Custom Visualizations apps End of Life for SimpleXML will reach end of support on Dec 21, 2024, ...

Introducing Splunk Enterprise 9.2

WATCH HERE! Watch this Tech Talk to learn about the latest features and enhancements shipped in the new Splunk ...

Adoption of RUM and APM at Splunk

    Unleash the power of Splunk Observability   Watch Now In this can't miss Tech Talk! The Splunk Growth ...