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!

Say goodbye to manually analyzing phishing and malware threats with Splunk Attack ...

In today’s evolving threat landscape, we understand you’re constantly bombarded with phishing and malware ...

AppDynamics is now part of Splunk Ideas

Hello Splunkers, We have exciting news for you! AppDynamics has been added to the Splunk Ideas Portal. Which ...

Advanced Splunk Data Management Strategies

Join us on Wednesday, May 14, 2025, at 11 AM PDT / 2 PM EDT for an exclusive Tech Talk that delves into ...