Splunk Search

What is the best way to use if clause with where?

appsik
Explorer

Hello Community,

I have a table:

Filename Status

file1             1

file2             0

 

 

| eval Status=if(where Status = 0, "missing file", Status)

 

 

If Status = 0 I want to replace 0 with "missing file".

Filename         Status

file2             file missing

What is the best way to do this?

Thanks in advance

Labels (1)
Tags (1)
0 Karma
1 Solution

javiergn
Super Champion

Hi @appsik , your logic is good but there is a typo in your SPL. It should be:

| eval Status=if(Status = 0, "missing file", Status)


Or if you wanted to do partial matching or regex matching you could use match instead:

 

| eval Status=if(match(Status, "MyRegex"), "missing file", Status)

 

Hi hope that helps.

 

View solution in original post

0 Karma

appsik
Explorer

Thank you very much

0 Karma

javiergn
Super Champion

Hi @appsik , your logic is good but there is a typo in your SPL. It should be:

| eval Status=if(Status = 0, "missing file", Status)


Or if you wanted to do partial matching or regex matching you could use match instead:

 

| eval Status=if(match(Status, "MyRegex"), "missing file", Status)

 

Hi hope that helps.

 

0 Karma
Get Updates on the Splunk Community!

Optimize Cloud Monitoring

  TECH TALKS Optimize Cloud Monitoring Tuesday, August 13, 2024  |  11:00AM–12:00PM PST   Register to ...

What's New in Splunk Cloud Platform 9.2.2403?

Hi Splunky people! We are excited to share the newest updates in Splunk Cloud Platform 9.2.2403! Analysts can ...

Stay Connected: Your Guide to July and August Tech Talks, Office Hours, and Webinars!

Dive into our sizzling summer lineup for July and August Community Office Hours and Tech Talks. Scroll down to ...