<?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 to use eval with IF? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-to-use-eval-with-IF/m-p/334280#M99345</link>
    <description>&lt;P&gt;The format I use for this is:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;...|eval  A=if(like(source,"%source_a.csv"), "1" , "0")
&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Thu, 25 Jan 2018 16:09:49 GMT</pubDate>
    <dc:creator>nickhills</dc:creator>
    <dc:date>2018-01-25T16:09:49Z</dc:date>
    <item>
      <title>How to use eval with IF?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-use-eval-with-IF/m-p/334276#M99341</link>
      <description>&lt;P&gt;&lt;CODE&gt;eval A=if(source == "source_a.csv", "1" , "0")&lt;/CODE&gt;&lt;/P&gt;

&lt;P&gt;The result is 0 in every entry. What is wrong?&lt;BR /&gt;
I have two sources &lt;CODE&gt;source_a.csv and source_b.csv&lt;/CODE&gt;, so there must be entries with 1 and 0?&lt;/P&gt;</description>
      <pubDate>Thu, 25 Jan 2018 10:55:02 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-use-eval-with-IF/m-p/334276#M99341</guid>
      <dc:creator>LH_SPLUNK</dc:creator>
      <dc:date>2018-01-25T10:55:02Z</dc:date>
    </item>
    <item>
      <title>Re: How to use eval with IF?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-use-eval-with-IF/m-p/334277#M99342</link>
      <description>&lt;P&gt;are you sure that source_a.csv is in any of the events? it is spelled correctly? have you tried with only one &lt;STRONG&gt;=&lt;/STRONG&gt; instead of &lt;STRONG&gt;==&lt;/STRONG&gt;, not that it should make a difference at all. also, what version of splunk are you on?&lt;/P&gt;</description>
      <pubDate>Thu, 25 Jan 2018 12:54:10 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-use-eval-with-IF/m-p/334277#M99342</guid>
      <dc:creator>cmerriman</dc:creator>
      <dc:date>2018-01-25T12:54:10Z</dc:date>
    </item>
    <item>
      <title>Re: How to use eval with IF?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-use-eval-with-IF/m-p/334278#M99343</link>
      <description>&lt;P&gt;No need to add a double == sign. Just source="filter-string" will do. But that shouldn't break things (at least it doesn't in my test box).&lt;/P&gt;

&lt;P&gt;Are you sure those are the source values of your events? Just the filename, no path included? Can you provide a screenshot of the actual event with the source field visible?&lt;/P&gt;</description>
      <pubDate>Thu, 25 Jan 2018 13:13:24 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-use-eval-with-IF/m-p/334278#M99343</guid>
      <dc:creator>FrankVl</dc:creator>
      <dc:date>2018-01-25T13:13:24Z</dc:date>
    </item>
    <item>
      <title>Re: How to use eval with IF?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-use-eval-with-IF/m-p/334279#M99344</link>
      <description>&lt;P&gt;I've tried a few settings.&lt;BR /&gt;
What can be, that the source_a.csv has a path in the field, like in the metrics.log example (source =   /opt/splunk/var/log/splunk/metrics.log) , if so then you could use this if pattern.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=_internal
| eval a=if(source like "%metrics.log","1","0")
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;If the field source is only "source_a.csv", then you can use the noted if pattern.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;    index=_internal
    | eval a=if(source="metrics.log","1","0")
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 25 Jan 2018 15:06:12 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-use-eval-with-IF/m-p/334279#M99344</guid>
      <dc:creator>Elsurion</dc:creator>
      <dc:date>2018-01-25T15:06:12Z</dc:date>
    </item>
    <item>
      <title>Re: How to use eval with IF?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-use-eval-with-IF/m-p/334280#M99345</link>
      <description>&lt;P&gt;The format I use for this is:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;...|eval  A=if(like(source,"%source_a.csv"), "1" , "0")
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 25 Jan 2018 16:09:49 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-use-eval-with-IF/m-p/334280#M99345</guid>
      <dc:creator>nickhills</dc:creator>
      <dc:date>2018-01-25T16:09:49Z</dc:date>
    </item>
    <item>
      <title>Re: How to use eval with IF?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-use-eval-with-IF/m-p/334281#M99346</link>
      <description>&lt;P&gt;@LH_SPLUNK, ususally &lt;CODE&gt;source&lt;/CODE&gt; name is fully qualified path of your source i.e. besides the file name it will also contain the path details. So, your condition should not find an exact match of the source filename rather than it should be a pattern of ending with filename. Following is a run anywhere example illustrating the difference in your approach vs regular expression pattern match for source using &lt;CODE&gt;match()&lt;/CODE&gt;&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| makeresults
| eval source="source_a.csv,source_b.csv,/blah/blah/source_a.csv,/blah/blah/source_b.csv"
| makemv source delim=","
| mvexpand source
| eval A=if(source == "source_a.csv", "1" , "0")
| eval B=case(match(source,"source_a.csv$"),"1",match(source,"source_b.csv$"),"0")
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;PS: &lt;CODE&gt;like()&lt;/CODE&gt; option suggested by @nickhillscpl, should also work. &lt;CODE&gt;match()&lt;/CODE&gt; is case sensitive.&lt;/P&gt;</description>
      <pubDate>Thu, 25 Jan 2018 16:28:50 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-use-eval-with-IF/m-p/334281#M99346</guid>
      <dc:creator>niketn</dc:creator>
      <dc:date>2018-01-25T16:28:50Z</dc:date>
    </item>
    <item>
      <title>Re: How to use eval with IF?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-use-eval-with-IF/m-p/528380#M149192</link>
      <description>&lt;P&gt;Thanks for the above info about using like. I ran into this issue when trying to match a field value inside an if.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;eval Environment=if( host="*beta*","BETA","PROD" )&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This returns all events with the Environment field value as PROD.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;It worked as expected once I changed to:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;if( like( host, "%beta%" ), "BETA", "PROD" )&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 07 Nov 2020 00:16:50 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-use-eval-with-IF/m-p/528380#M149192</guid>
      <dc:creator>yobackman</dc:creator>
      <dc:date>2020-11-07T00:16:50Z</dc:date>
    </item>
  </channel>
</rss>

