Splunk Search

How to solve this issue with eval if?

SumanPalisetty
Path Finder

Hi,

I am facing an issue with the eval if condition. Please help.

 

index=main, source=ls.csv
| eval new_field = if(error=200,"sc","cs",if(error=500,"css","ssc"))
| table error new_field

 

 

erro.png

Regards

Suman P.

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

richgalloway
SplunkTrust
SplunkTrust

There are too many arguments to the first if.  Each if function can have only 3 arguments - an expression to test, the value to set if true, and the value to set if false.  If you want nested ifs then it needs to look more like this:

| eval new_field = if(error=200,"sc", if(error=500,"css","ssc"))
---
If this reply helps you, Karma would be appreciated.

View solution in original post

richgalloway
SplunkTrust
SplunkTrust

There are too many arguments to the first if.  Each if function can have only 3 arguments - an expression to test, the value to set if true, and the value to set if false.  If you want nested ifs then it needs to look more like this:

| eval new_field = if(error=200,"sc", if(error=500,"css","ssc"))
---
If this reply helps you, Karma would be appreciated.
Get Updates on the Splunk Community!

More Ways To Control Your Costs With Archived Metrics | Register for Tech Talk

Tuesday, May 14, 2024  |  11AM PT / 2PM ET Register to Attend Join us for this Tech Talk and learn how to ...

.conf24 | Personalize your .conf experience with Learning Paths!

Personalize your .conf24 Experience Learning paths allow you to level up your skill sets and dive deeper ...

Threat Hunting Unlocked: How to Uplevel Your Threat Hunting With the PEAK Framework ...

WATCH NOWAs AI starts tackling low level alerts, it's more critical than ever to uplevel your threat hunting ...