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!

Join Us for Splunk University and Get Your Bootcamp Game On!

If you know, you know! Splunk University is the vibe this summer so register today for bootcamps galore ...

.conf24 | Learning Tracks for Security, Observability, Platform, and Developers!

.conf24 is taking place at The Venetian in Las Vegas from June 11 - 14. Continue reading to learn about the ...

Announcing Scheduled Export GA for Dashboard Studio

We're excited to announce the general availability of Scheduled Export for Dashboard Studio. Starting in ...