Splunk Enterprise

Help on eval if from eval case

jip31
Motivator

Hi

As you can see, I use a first eval in order to rename the field "site"

From the site renamed, I need to create a new field called "toto" in order to add new information for the field site.

So I create an eval if command like below but it doesn't work.

What is wrong please and is there another simple way to do this?

 

| eval site=case(site=="BR", "Espace Br", site=="PERI THEATRE", "Espace Périg", 1==1,site)
| stats last(site) as "Espace BP" by s
| eval toto=if("Espace BP"=="Espace Br", "4G") 
| table "Espace BPE" toto 

 

 

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

richgalloway
SplunkTrust
SplunkTrust

The if function is comparing two different strings and setting a value only if they are equal.  Therefore, toto is always null.

Use single quotes around a field name containing spaces.

| eval site=case(site=="BR", "Espace Br", site=="PERI THEATRE", "Espace Périg", 1==1,site)
| stats last(site) as "Espace BP" by s
| eval toto=if('Espace BP'=="Espace Br", "4G") 
| table "Espace BPE" toto 

Better yet, don't use spaces in field names at all.  Add a final rename command in the query to make the names "pretty".

---
If this reply helps you, Karma would be appreciated.

View solution in original post

richgalloway
SplunkTrust
SplunkTrust

The if function is comparing two different strings and setting a value only if they are equal.  Therefore, toto is always null.

Use single quotes around a field name containing spaces.

| eval site=case(site=="BR", "Espace Br", site=="PERI THEATRE", "Espace Périg", 1==1,site)
| stats last(site) as "Espace BP" by s
| eval toto=if('Espace BP'=="Espace Br", "4G") 
| table "Espace BPE" toto 

Better yet, don't use spaces in field names at all.  Add a final rename command in the query to make the names "pretty".

---
If this reply helps you, Karma would be appreciated.
Get Updates on the Splunk Community!

Index This | I am a number, but when you add ‘G’ to me, I go away. What number am I?

March 2024 Edition Hayyy Splunk Education Enthusiasts and the Eternally Curious!  We’re back with another ...

What’s New in Splunk App for PCI Compliance 5.3.1?

The Splunk App for PCI Compliance allows customers to extend the power of their existing Splunk solution with ...

Extending Observability Content to Splunk Cloud

Register to join us !   In this Extending Observability Content to Splunk Cloud Tech Talk, you'll see how to ...