Getting Data In

How to create Conditional statements with foreach?

allanrm
Observer

Hi there -  trying to get foreach statement to apply conditional statement. Essentialy in the eval statement tried a variety of if with options like IN statements (or alternatively but less preferably a long OR to replace the IN statement )-  but frankly not having any luck.

 foreach Perc_In* [ eval Out_Of_Norm_For<<MATCHSTR>>=if(IN(<<MATCHSTR>>,"_Range_4","_RANGE_4_to_6"),"Consider","Ignore") ] 

If the <<matchstr>> falls in the set of values "_Range_4" or  "_RANGE_4to_6", then the new field  Out_Of_Norm_For<<MATCHSTR>> should take a value of consider - else it takes a value of Ignore

Labels (1)
Tags (2)
0 Karma

bowesmana
SplunkTrust
SplunkTrust

Quote the <<MATCHSTR>>

| makeresults
| eval Perc_In_Range_4=100
| eval Perc_In_Range_4_to_6=11
| eval Perc_In_RANGE_4_to_6=22
| foreach Perc_In* [ eval Out_Of_Norm_For<<MATCHSTR>>=if(IN("<<MATCHSTR>>","_Range_4","_RANGE_4_to_6"),"Consider","Ignore") ]

Note that the IN in eval will be case sensitive, i.e. Perc_In_Range_4_to_6 will be "Ignore"

0 Karma
Get Updates on the Splunk Community!

Built-in Service Level Objectives Management to Bridge the Gap Between Service & ...

Wednesday, May 29, 2024  |  11AM PST / 2PM ESTRegister now and join us to learn more about how you can ...

Get Your Exclusive Splunk Certified Cybersecurity Defense Engineer Certification at ...

We’re excited to announce a new Splunk certification exam being released at .conf24! If you’re headed to Vegas ...

Share Your Ideas & Meet the Lantern team at .Conf! Plus All of This Month’s New ...

Splunk Lantern is Splunk’s customer success center that provides advice from Splunk experts on valuable data ...