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!

.conf25 technical session recap of Observability for Gen AI: Monitoring LLM ...

If you’re unfamiliar, .conf is Splunk’s premier event where the Splunk community, customers, partners, and ...

A Season of Skills: New Splunk Courses to Light Up Your Learning Journey

There’s something special about this time of year—maybe it’s the glow of the holidays, maybe it’s the ...

Announcing the Migration of the Splunk Add-on for Microsoft Azure Inputs to ...

Announcing the Migration of the Splunk Add-on for Microsoft Azure Inputs to Officially Supported Splunk ...