<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: How do I edit my eval syntax with multiple if conditions to produce a certain field? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-do-I-edit-my-eval-syntax-with-multiple-if-conditions-to/m-p/277061#M83561</link>
    <description>&lt;P&gt;There's no "you should use eval case", it's a preference in my humble opinion.&lt;/P&gt;

&lt;P&gt;Did you try my search?&lt;/P&gt;</description>
    <pubDate>Mon, 31 Oct 2016 14:17:13 GMT</pubDate>
    <dc:creator>jkat54</dc:creator>
    <dc:date>2016-10-31T14:17:13Z</dc:date>
    <item>
      <title>How do I edit my eval syntax with multiple if conditions to produce a certain field?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-I-edit-my-eval-syntax-with-multiple-if-conditions-to/m-p/277055#M83555</link>
      <description>&lt;P&gt;Hi all.&lt;/P&gt;

&lt;P&gt;I have a ruleset like this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;MODEL_NUMBER1 AND BTT = SUBTYPE1
MODEL_NUMBER2 AND CTT = SUBTYPE2
MODEL_NUMBER3 AND RTT = SUBTYPE3
MODEL_NUMBER4 AND PTT = SUBTYPE4
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;My dataset has the MODEL_NUMBER value in 5 fields (&lt;CODE&gt;IP_TYPE1...IP_TYPE5&lt;/CODE&gt;) and the other value in the field &lt;CODE&gt;IP_KIND&lt;/CODE&gt;.&lt;/P&gt;

&lt;P&gt;I need to produce a resulting field with the same logic in a new field. I am doing something like this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;sourcetype=temp | 
eval RESULTING_FIELD = if(IP_TYPE1 == "MODEL NUMBER 1" OR IP_TYPE2 == "MODEL NUMBER 1" OR IP_TYPE3 == "MODEL NUMBER 1" OR IP_TYPE4 == "MODEL NUMBER 1" OR IP_TYPE5 == "MODEL NUMBER 1" AND IP_KIND == "BTT", "SUBTYPE1", "OTHER")
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Works fine for the first subtype, but how I can produce a complete sentence with all fields? I tried with case without success (no OTHER).&lt;/P&gt;

&lt;P&gt;Thanks!&lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2020 11:34:39 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-I-edit-my-eval-syntax-with-multiple-if-conditions-to/m-p/277055#M83555</guid>
      <dc:creator>changux</dc:creator>
      <dc:date>2020-09-29T11:34:39Z</dc:date>
    </item>
    <item>
      <title>Re: How do I edit my eval syntax with multiple if conditions to produce a certain field?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-I-edit-my-eval-syntax-with-multiple-if-conditions-to/m-p/277056#M83556</link>
      <description>&lt;PRE&gt;&lt;CODE&gt;See if this works: (put those ORs in parenthesis)

 sourcetype=temp | 
 eval RESULTING_FIELD = if((IP_TYPE1 == "MODEL NUMBER 1" OR IP_TYPE2 == "MODEL NUMBER 1" OR IP_TYPE3 == "MODEL NUMBER 1" OR IP_TYPE4 == "MODEL NUMBER 1" OR IP_TYPE5 == "MODEL NUMBER 1") AND IP_KIND == "BTT", "SUBTYPE1", "OTHER")
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 30 Oct 2016 22:22:44 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-I-edit-my-eval-syntax-with-multiple-if-conditions-to/m-p/277056#M83556</guid>
      <dc:creator>jkat54</dc:creator>
      <dc:date>2016-10-30T22:22:44Z</dc:date>
    </item>
    <item>
      <title>Re: How do I edit my eval syntax with multiple if conditions to produce a certain field?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-I-edit-my-eval-syntax-with-multiple-if-conditions-to/m-p/277057#M83557</link>
      <description>&lt;P&gt;Or maybe I'm misunderstanding your request here.&lt;/P&gt;

&lt;P&gt;If you're trying to have the same if but for model number 2, 3, etc...  Try this&lt;/P&gt;

&lt;P&gt;first zip the fields into one field to help shorten your if/case statement:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt; |eval a=mvzip(IP_TYPE1,IP_TYPE2) | eval b=mvzip(IP_TYPE3,IP_TYPE4)| eval c=mvzip(a,b) | eval d=mvzip(c,IP_TYPE5) 
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Then use if/case with match:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;   | eval result=if((match(d,".*MODEL NUMBER 1.*") AND IP_KIND=="BTT"),"Subtype1",if((match(d,".*MODEL NUMBER 2.*") AND IP_KIND=="BTT"),"subtype2","other"))
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;For each other subtype replace "other" with another if match statement.  Just remember to add another ending parens ")" at the end for each if you start.&lt;/P&gt;

&lt;P&gt;It's usually the syntax that gets you on these long if or case statements.&lt;/P&gt;</description>
      <pubDate>Sun, 30 Oct 2016 22:35:49 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-I-edit-my-eval-syntax-with-multiple-if-conditions-to/m-p/277057#M83557</guid>
      <dc:creator>jkat54</dc:creator>
      <dc:date>2016-10-30T22:35:49Z</dc:date>
    </item>
    <item>
      <title>Re: How do I edit my eval syntax with multiple if conditions to produce a certain field?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-I-edit-my-eval-syntax-with-multiple-if-conditions-to/m-p/277058#M83558</link>
      <description>&lt;P&gt;Since you're more than 2 condition, you should &lt;CODE&gt;eval-case&lt;/CODE&gt; instead of &lt;CODE&gt;eval-if&lt;/CODE&gt;. Like this&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt; sourcetype=temp | 
 eval RESULTING_FIELD = if((IP_TYPE1="MODEL NUMBER 1" OR IP_TYPE2="MODEL NUMBER 1" OR IP_TYPE3="MODEL NUMBER 1" OR IP_TYPE4="MODEL NUMBER 1" OR IP_TYPE5="MODEL NUMBER 1") AND IP_KIND="BTT", "SUBTYPE1", (IP_TYPE1="MODEL NUMBER 2" OR IP_TYPE2="MODEL NUMBER 2" OR IP_TYPE3="MODEL NUMBER 2" OR IP_TYPE4="MODEL NUMBER 2" OR IP_TYPE5="MODEL NUMBER 2") AND IP_KIND="CTT", "SUBTYPE2", (IP_TYPE1="MODEL NUMBER 3" OR IP_TYPE2="MODEL NUMBER 3" OR IP_TYPE3="MODEL NUMBER 3" OR IP_TYPE4="MODEL NUMBER 3" OR IP_TYPE5="MODEL NUMBER 3") AND IP_KIND="RTT", "SUBTYPE3", (IP_TYPE1="MODEL NUMBER 4" OR IP_TYPE2="MODEL NUMBER 4" OR IP_TYPE3="MODEL NUMBER 4" OR IP_TYPE4="MODEL NUMBER 4" OR IP_TYPE5="MODEL NUMBER 4") AND IP_KIND="PTT", "SUBTYPE4", true(),"OTHER")
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 31 Oct 2016 00:04:19 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-I-edit-my-eval-syntax-with-multiple-if-conditions-to/m-p/277058#M83558</guid>
      <dc:creator>somesoni2</dc:creator>
      <dc:date>2016-10-31T00:04:19Z</dc:date>
    </item>
    <item>
      <title>Re: How do I edit my eval syntax with multiple if conditions to produce a certain field?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-I-edit-my-eval-syntax-with-multiple-if-conditions-to/m-p/277059#M83559</link>
      <description>&lt;P&gt;Thanks. You mean:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;  sourcetype=temp | 
  eval RESULTING_FIELD = case((IP_TYPE1="MODEL NUMBER 1" OR IP_TYPE2="MODEL NUMBER 1" OR IP_TYPE3="MODEL NUMBER 1" OR IP_TYPE4="MODEL NUMBER 1" OR IP_TYPE5="MODEL NUMBER 1") AND IP_KIND="BTT", "SUBTYPE1", (IP_TYPE1="MODEL NUMBER 2" OR IP_TYPE2="MODEL NUMBER 2" OR IP_TYPE3="MODEL NUMBER 2" OR IP_TYPE4="MODEL NUMBER 2" OR IP_TYPE5="MODEL NUMBER 2") AND IP_KIND="CTT", "SUBTYPE2", (IP_TYPE1="MODEL NUMBER 3" OR IP_TYPE2="MODEL NUMBER 3" OR IP_TYPE3="MODEL NUMBER 3" OR IP_TYPE4="MODEL NUMBER 3" OR IP_TYPE5="MODEL NUMBER 3") AND IP_KIND="RTT", "SUBTYPE3", (IP_TYPE1="MODEL NUMBER 4" OR IP_TYPE2="MODEL NUMBER 4" OR IP_TYPE3="MODEL NUMBER 4" OR IP_TYPE4="MODEL NUMBER 4" OR IP_TYPE5="MODEL NUMBER 4") AND IP_KIND="PTT", "SUBTYPE4", true(),"OTHER")
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;My resulting field only shows OTHER, any idea?&lt;/P&gt;</description>
      <pubDate>Mon, 31 Oct 2016 02:14:40 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-I-edit-my-eval-syntax-with-multiple-if-conditions-to/m-p/277059#M83559</guid>
      <dc:creator>changux</dc:creator>
      <dc:date>2016-10-31T02:14:40Z</dc:date>
    </item>
    <item>
      <title>Re: How do I edit my eval syntax with multiple if conditions to produce a certain field?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-I-edit-my-eval-syntax-with-multiple-if-conditions-to/m-p/277060#M83560</link>
      <description>&lt;P&gt;Solved, problem with accents into IP_TYPE strings.&lt;/P&gt;</description>
      <pubDate>Mon, 31 Oct 2016 02:30:18 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-I-edit-my-eval-syntax-with-multiple-if-conditions-to/m-p/277060#M83560</guid>
      <dc:creator>changux</dc:creator>
      <dc:date>2016-10-31T02:30:18Z</dc:date>
    </item>
    <item>
      <title>Re: How do I edit my eval syntax with multiple if conditions to produce a certain field?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-I-edit-my-eval-syntax-with-multiple-if-conditions-to/m-p/277061#M83561</link>
      <description>&lt;P&gt;There's no "you should use eval case", it's a preference in my humble opinion.&lt;/P&gt;

&lt;P&gt;Did you try my search?&lt;/P&gt;</description>
      <pubDate>Mon, 31 Oct 2016 14:17:13 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-I-edit-my-eval-syntax-with-multiple-if-conditions-to/m-p/277061#M83561</guid>
      <dc:creator>jkat54</dc:creator>
      <dc:date>2016-10-31T14:17:13Z</dc:date>
    </item>
    <item>
      <title>Re: How do I edit my eval syntax with multiple if conditions to produce a certain field?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-I-edit-my-eval-syntax-with-multiple-if-conditions-to/m-p/277062#M83562</link>
      <description>&lt;P&gt;Please choose an answer for this question&lt;/P&gt;</description>
      <pubDate>Fri, 01 Mar 2019 19:27:13 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-I-edit-my-eval-syntax-with-multiple-if-conditions-to/m-p/277062#M83562</guid>
      <dc:creator>ryhluc01</dc:creator>
      <dc:date>2019-03-01T19:27:13Z</dc:date>
    </item>
  </channel>
</rss>

