Splunk Search

Compare three column values and evaluate fourth

NS
Explorer

Hey Splunkers!

Please help me with the below query.

I have the below table, and i want to create a new column based on the existing column values:

Column1Column2Column3Result
AppleGrapeCherryFruits
SpinachPotatoRaddishVegetables

 

The Result column is the one Im looking to derive with the below query:

| eval Result = if(column1="Apple" OR column2="Grape" OR column3="Cherry" , "Fruits", column1="Spinach" OR column2="Potato" OR column3="Raddish" , "Vegetables",1==1, "Unknown")

However im getting an error, can someone please help?

Much appreciated.

Thanks!

Labels (1)
0 Karma
1 Solution

kamlesh_vaghela
SplunkTrust
SplunkTrust

@NS 

 

Try this,

YOUR_SEARCH
|eval Result = case(Column1="Apple" OR Column2="Grape" OR Column3="Cherry", "Fruits", Column1="Spinach" OR Column2="Potato" OR Column3="Raddish" , "Vegetables",1==1, "Unknown")

 

Sample Search:

 

| makeresults | eval _raw="
Column1	Column2	Column3
Apple	Grape	Cherry
Spinach	Potato	Raddish"
| multikv forceheader=1
|eval Result = case(Column1="Apple" OR Column2="Grape" OR Column3="Cherry", "Fruits", Column1="Spinach" OR Column2="Potato" OR Column3="Raddish" , "Vegetables",1==1, "Unknown")

 

View solution in original post

kamlesh_vaghela
SplunkTrust
SplunkTrust

@NS 

 

Try this,

YOUR_SEARCH
|eval Result = case(Column1="Apple" OR Column2="Grape" OR Column3="Cherry", "Fruits", Column1="Spinach" OR Column2="Potato" OR Column3="Raddish" , "Vegetables",1==1, "Unknown")

 

Sample Search:

 

| makeresults | eval _raw="
Column1	Column2	Column3
Apple	Grape	Cherry
Spinach	Potato	Raddish"
| multikv forceheader=1
|eval Result = case(Column1="Apple" OR Column2="Grape" OR Column3="Cherry", "Fruits", Column1="Spinach" OR Column2="Potato" OR Column3="Raddish" , "Vegetables",1==1, "Unknown")

 

ITWhisperer
SplunkTrust
SplunkTrust

"if" should be "case"

Get Updates on the Splunk Community!

Modernize your Splunk Apps – Introducing Python 3.13 in Splunk

We are excited to announce that the upcoming releases of Splunk Enterprise 10.2.x and Splunk Cloud Platform ...

New Release | Splunk Cloud Platform 10.1.2507

Hello Splunk Community!We are thrilled to announce the General Availability of Splunk Cloud Platform 10.1.2507 ...

🌟 From Audit Chaos to Clarity: Welcoming Audit Trail v2

🗣 You Spoke, We Listened  Audit Trail v2 wasn’t written in isolation—it was shaped by your voices.  In ...