Splunk Search

How do you create an if statement without the else?

zikpefu
New Member

I am producing a table that will monitor what various users are searching for and I am trying to limit the amount of characters the result is to 15 letters (using the eval statement).

I am trying to use this syntax:

|eval field_name= if(len(field_name) > 15," ", ???)

Any help would be appreciated

0 Karma
1 Solution

pradeepkumarg
Influencer

This works?

|eval field_name= if(len(field_name) > 15," ", field_name)

You just retain what's there in the field if the length is not greater than 15.

View solution in original post

0 Karma

@zikpefu, If the length of field_name>15 then do you want to truncate to first 15 characters or make it blank?

If you want to get only up to first 15 characters you can just use substr() evaluation function.

<yourCurrentSearch>
| eval field_name=substr(field_name,1,15) 

If you want if/else condition you can try something like the following:

<yourCurrentSearch>
| eval field_name=if(len(field_name)>15,substr(field_name,1,15),field_name)

Following is a run anywhere search for you to try out

| makeresults
| eval field_name="38927498327321425,287489364"
| makemv field_name delim=","
| mvexpand field_name
| eval result=if(len(field_name)>15,substr(field_name,1,15),field_name)
____________________________________________
| makeresults | eval message= "Happy Splunking!!!"
0 Karma

pradeepkumarg
Influencer

This works?

|eval field_name= if(len(field_name) > 15," ", field_name)

You just retain what's there in the field if the length is not greater than 15.

0 Karma
Get Updates on the Splunk Community!

New Cloud Intrusion Detection System Add-on for Splunk

In July 2022 Splunk released the Cloud IDS add-on which expanded Splunk capabilities in security and data ...

Happy CX Day to our Community Superheroes!

Happy 10th Birthday CX Day!What is CX Day? It’s a global celebration recognizing innovation and success in the ...

Check out This Month’s Brand new Splunk Lantern Articles

Splunk Lantern is a customer success center providing advice from Splunk experts on valuable data insights, ...