Splunk Search

Escaping Underscore inside "like"

bruceclarke
Contributor

All,

I'm trying to write a search that does something like the following:

[some search] | eval option=case(like(field,"%_Blah"), field, 1=1, "Other")

So, I want to return anything that ends with "_Blah". The problem is that I also have a value that is "_OtherBlah" which is being matched. I'm assuming I need to do something to escape the underscore, but I can't seem to find how to do it. A backslash or putting the underscore in brackets won't work.

Can someone help?

Thanks!

0 Karma
1 Solution

lguinn2
Legend

I would do it like this:

yoursearchhere
| eval option=if(match(field,"_Blah$"),field,"Other")

This uses a regular expression for the test. I also think that the if function is a little easier to read than case in this example.

View solution in original post

lguinn2
Legend

I would do it like this:

yoursearchhere
| eval option=if(match(field,"_Blah$"),field,"Other")

This uses a regular expression for the test. I also think that the if function is a little easier to read than case in this example.

bruceclarke
Contributor

Works great! Thank you!

0 Karma
Get Updates on the Splunk Community!

Updated Team Landing Page in Splunk Observability

We’re making some changes to the team landing page in Splunk Observability, based on your feedback. The ...

New! Splunk Observability Search Enhancements for Splunk APM Services/Traces and ...

Regardless of where you are in Splunk Observability, you can search for relevant APM targets including service ...

Webinar Recap | Revolutionizing IT Operations: The Transformative Power of AI and ML ...

The Transformative Power of AI and ML in Enhancing Observability   In the realm of IT operations, the ...