Splunk Search

If a value contains a value it changes to another.

Talking_Master
Explorer

Hi Iam looking to create an if statement:  if value  contains part of another value  it changes it too another value.

for example contains x its true if not its false.   

 | eval error=if(in(status, "error", "failure", "severe"),"true","false")

I also want it for many values.

Labels (1)
0 Karma
1 Solution

andrew_nelson
Communicator

Using the match() function should do what you need. 

| eval error=if(match(status, "(?i)error") OR match(status, "(?i)failure") OR match(status, "(?i)severe"),"true","false")

 

If however you have a bunch of matching patterns, having all of them in a lookup file and using wildcard matching might be a better option. 

View solution in original post

andrew_nelson
Communicator

Using the match() function should do what you need. 

| eval error=if(match(status, "(?i)error") OR match(status, "(?i)failure") OR match(status, "(?i)severe"),"true","false")

 

If however you have a bunch of matching patterns, having all of them in a lookup file and using wildcard matching might be a better option. 

Talking_Master
Explorer

Thanks for the solution. But If theres value say it has  server 1 failed. How do I one look for if value has failed in its string then it does somthing.

 

0 Karma

andrew_nelson
Communicator

You can use match(status, "(?i)fail") and it'll match failed, fail, failure, failing.

Career Survey
First 500 qualified respondents will receive a $20 gift card! Tell us about your professional Splunk journey.

Can’t make it to .conf25? Join us online!

Get Updates on the Splunk Community!

Community Content Calendar, September edition

Welcome to another insightful post from our Community Content Calendar! We're thrilled to continue bringing ...

Splunkbase Unveils New App Listing Management Public Preview

Splunkbase Unveils New App Listing Management Public PreviewWe're thrilled to announce the public preview of ...

Leveraging Automated Threat Analysis Across the Splunk Ecosystem

Are you leveraging automation to its fullest potential in your threat detection strategy?Our upcoming Security ...