<?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 Eval If Statement in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Eval-If-Statement/m-p/242808#M72238</link>
    <description>&lt;P&gt;Hi, I wonder whether someone may be able to help me please.&lt;/P&gt;

&lt;P&gt;Although I've been using Splunk for a few months now, I'm still coming against statements I've not see before. &lt;/P&gt;

&lt;P&gt;One of which is this &lt;CODE&gt;| eval verifiedButBounced=if('detail.verifiedButBounced'!="", 'detail.verifiedButBounced.count',0)&lt;/CODE&gt;&lt;/P&gt;

&lt;P&gt;Could someone possibly explain to me what this statement is actually doing and is there a more efficient way of writing this.&lt;/P&gt;

&lt;P&gt;Many thanks and kind regards&lt;/P&gt;

&lt;P&gt;Chris&lt;/P&gt;</description>
    <pubDate>Wed, 16 Mar 2016 08:10:33 GMT</pubDate>
    <dc:creator>IRHM73</dc:creator>
    <dc:date>2016-03-16T08:10:33Z</dc:date>
    <item>
      <title>Eval If Statement</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Eval-If-Statement/m-p/242808#M72238</link>
      <description>&lt;P&gt;Hi, I wonder whether someone may be able to help me please.&lt;/P&gt;

&lt;P&gt;Although I've been using Splunk for a few months now, I'm still coming against statements I've not see before. &lt;/P&gt;

&lt;P&gt;One of which is this &lt;CODE&gt;| eval verifiedButBounced=if('detail.verifiedButBounced'!="", 'detail.verifiedButBounced.count',0)&lt;/CODE&gt;&lt;/P&gt;

&lt;P&gt;Could someone possibly explain to me what this statement is actually doing and is there a more efficient way of writing this.&lt;/P&gt;

&lt;P&gt;Many thanks and kind regards&lt;/P&gt;

&lt;P&gt;Chris&lt;/P&gt;</description>
      <pubDate>Wed, 16 Mar 2016 08:10:33 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Eval-If-Statement/m-p/242808#M72238</guid>
      <dc:creator>IRHM73</dc:creator>
      <dc:date>2016-03-16T08:10:33Z</dc:date>
    </item>
    <item>
      <title>Re: Eval If Statement</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Eval-If-Statement/m-p/242809#M72239</link>
      <description>&lt;P&gt;So the &lt;CODE&gt;eval&lt;/CODE&gt; command's &lt;CODE&gt;if&lt;/CODE&gt; works just like the &lt;CODE&gt;IF&lt;/CODE&gt; macro in Excel.  The idea here the search is trying to "zero-fill" a field if the contents of the field is the empty string.  This is a fairly common idiom, and can sometimes be replaced with the &lt;CODE&gt;coalesce&lt;/CODE&gt; function like so:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| eval verifiedButBounced = coalesce('detail.verifiedButBounced',0)
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;The trickery here is the use of both &lt;CODE&gt;"&lt;/CODE&gt; and &lt;CODE&gt;'&lt;/CODE&gt;.  In &lt;CODE&gt;eval&lt;/CODE&gt;, a &lt;CODE&gt;.&lt;/CODE&gt; (dot) character can be used to mean string concatenation.  It can also be used in a field name, like if a field comes from JSON data.  So if you have the string &lt;CODE&gt;detail.verifiedButBounced&lt;/CODE&gt; do you mean a field named &lt;CODE&gt;detail.verifiedButBounced&lt;/CODE&gt; or do you mean &lt;CODE&gt;detail&lt;/CODE&gt; concatenated with &lt;CODE&gt;verifiedButBounced&lt;/CODE&gt;?  It is ambiguous!  The eval command uses a single-quote around a field name to "escape" otherwise special characters within that field name.  Double quotes are used to represent static strings.  So your original eval could be expressed as:&lt;/P&gt;

&lt;P&gt;If the field named &lt;CODE&gt;detail.verifiedButBounced&lt;/CODE&gt; is not equal to the string &lt;CODE&gt;""&lt;/CODE&gt; then set the new field &lt;CODE&gt;verifiedButBounced&lt;/CODE&gt; equal to the value of &lt;CODE&gt;detail.verifiedButBounced&lt;/CODE&gt;.  Otherwise, set the value of the new field &lt;CODE&gt;verifiedButBounced&lt;/CODE&gt; equal to 0.&lt;/P&gt;</description>
      <pubDate>Wed, 16 Mar 2016 08:35:38 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Eval-If-Statement/m-p/242809#M72239</guid>
      <dc:creator>dwaddle</dc:creator>
      <dc:date>2016-03-16T08:35:38Z</dc:date>
    </item>
    <item>
      <title>Re: Eval If Statement</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Eval-If-Statement/m-p/242810#M72240</link>
      <description>&lt;P&gt;Hi @dwaddle, for confirmation the "detail.verifiedButBounced" is the name of the field.&lt;/P&gt;

&lt;P&gt;Thank you very much for the confirmation on the steps the statement is taking, it's very useful and will certainly help in the future.&lt;/P&gt;

&lt;P&gt;Kind Regards&lt;/P&gt;

&lt;P&gt;Chris&lt;/P&gt;</description>
      <pubDate>Wed, 16 Mar 2016 09:04:37 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Eval-If-Statement/m-p/242810#M72240</guid>
      <dc:creator>IRHM73</dc:creator>
      <dc:date>2016-03-16T09:04:37Z</dc:date>
    </item>
  </channel>
</rss>

