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

niketn
Legend

@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!

Splunk Observability Cloud’s AI Assistant in Action Series: Analyzing and ...

This is the second post in our Splunk Observability Cloud’s AI Assistant in Action series, in which we look at ...

Elevate Your Organization with Splunk’s Next Platform Evolution

 Thursday, July 10, 2025  |  11AM PDT / 2PM EDT Whether you're managing complex deployments or looking to ...

Splunk Answers Content Calendar, June Edition

Get ready for this week’s post dedicated to Splunk Dashboards! We're celebrating the power of community by ...