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!

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

Take a look below to explore our upcoming Community Office Hours, Tech Talks, and Webinars this month. This ...

They're back! Join the SplunkTrust and MVP at .conf24

With our highly anticipated annual conference, .conf, comes the fez-wearers you can trust! The SplunkTrust, as ...

Enterprise Security Content Update (ESCU) | New Releases

Last month, the Splunk Threat Research Team had two releases of new security content via the Enterprise ...