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!

Demo Day: Strengthen Your SOC with Splunk Enterprise Security 8.1

Today’s threat landscape is more complex than ever. Security operation centers (SOCs) are overwhelmed with ...

Dashboards: Hiding charts while search is being executed and other uses for tokens

There are a couple of features of SimpleXML / Classic dashboards that can be used to enhance the user ...

Splunk Observability Cloud's AI Assistant in Action Series: Explaining Metrics and ...

This is the fourth post in the Splunk Observability Cloud’s AI Assistant in Action series that digs into how ...