{"id":42444,"date":"2021-08-31T21:09:04","date_gmt":"2021-08-31T21:09:04","guid":{"rendered":"https:\/\/merikebi.warrenmyers.com\/?p=42444"},"modified":"2021-08-31T21:09:04","modified_gmt":"2021-08-31T21:09:04","slug":"answer-by-warren-for-nested-if-loop-in-splunk","status":"publish","type":"post","link":"https:\/\/merikebi.warrenmyers.com\/?p=42444","title":{"rendered":"Answer by warren for nested if loop in splunk"},"content":{"rendered":"<p>SPL doesn&#8217;t do &quot;loops&quot;. A close [enough] analog is that each line in SPL is <em>similar<\/em> to a single command in bash (hence the pipe separator between commands). IOW, SPL is purely linear in processing. Use a multi-condition <a href=\"https:\/\/docs.splunk.com\/Documentation\/Splunk\/latest\/SearchReference\/eval\" rel=\"nofollow noreferrer\"><code>eval..if<\/code><\/a> like this:<\/p>\n<pre><code>index=ndx sourcetype=srctp \n| eval myfield=if(match(fieldA,&quot;someval&quot;) AND !match(fieldC,&quot;notthis&quot;),&quot;all true&quot;,&quot;else val&quot;)\n<\/code><\/pre>\n<p>Or like this:<\/p>\n<pre><code>| eval myfield=if(match(fieldA,&quot;someval&quot;),if(match(fieldB,&quot;otherval&quot;),&quot;matched A&amp;B&quot;,if(!match(fieldC,&quot;notthis&quot;),&quot;not A &amp; not C&quot;,&quot;else val&quot;)))\n<\/code><\/pre>\n<p>If you can explain your use case\/end goal better, we can probably provide better direction<\/p>\n<p>from User warren &#8211; Stack Overflow https:\/\/stackoverflow.com\/questions\/68978891\/nested-if-loop-in-splunk\/69005277#69005277<br \/>\nvia <a href=\"https:\/\/ifttt.com\/?ref=da&#038;site=wordpress\">IFTTT<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>SPL doesn&#8217;t do &quot;loops&quot;. A close [enough] analog is that each line in SPL is similar to a single command in bash (hence the pipe separator between commands). IOW, SPL is purely linear in processing. Use a multi-condition eval..if like this: index=ndx sourcetype=srctp | eval myfield=if(match(fieldA,&quot;someval&quot;) AND !match(fieldC,&quot;notthis&quot;),&quot;all true&quot;,&quot;else val&quot;) Or like this: | eval &hellip;<br \/><a href=\"https:\/\/merikebi.warrenmyers.com\/?p=42444\" class=\"more-link pen_button pen_element_default pen_icon_arrow_double\">Continue reading <span class=\"screen-reader-text\">Answer by warren for nested if loop in splunk<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[4],"tags":[991],"keyring_services":[],"class_list":["post-42444","post","type-post","status-publish","format-standard","hentry","category-blih","tag-stackexchange"],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/merikebi.warrenmyers.com\/index.php?rest_route=\/wp\/v2\/posts\/42444","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/merikebi.warrenmyers.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/merikebi.warrenmyers.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/merikebi.warrenmyers.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/merikebi.warrenmyers.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=42444"}],"version-history":[{"count":1,"href":"https:\/\/merikebi.warrenmyers.com\/index.php?rest_route=\/wp\/v2\/posts\/42444\/revisions"}],"predecessor-version":[{"id":42445,"href":"https:\/\/merikebi.warrenmyers.com\/index.php?rest_route=\/wp\/v2\/posts\/42444\/revisions\/42445"}],"wp:attachment":[{"href":"https:\/\/merikebi.warrenmyers.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=42444"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/merikebi.warrenmyers.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=42444"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/merikebi.warrenmyers.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=42444"},{"taxonomy":"keyring_services","embeddable":true,"href":"https:\/\/merikebi.warrenmyers.com\/index.php?rest_route=%2Fwp%2Fv2%2Fkeyring_services&post=42444"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}