<?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: Conditional searching using eval command in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Conditional-searching-using-eval-command/m-p/260980#M78312</link>
    <description>&lt;P&gt;Hi, your query is a bit confusing.&lt;BR /&gt;
Can you review and edit your question but using the Code Sample button (select your code then press the button with 1s and 0s) for your query in order to make sure no especial characters are omitted?&lt;/P&gt;

&lt;P&gt;Thanks,&lt;BR /&gt;
J&lt;/P&gt;</description>
    <pubDate>Tue, 02 Feb 2016 14:36:16 GMT</pubDate>
    <dc:creator>javiergn</dc:creator>
    <dc:date>2016-02-02T14:36:16Z</dc:date>
    <item>
      <title>Conditional searching using eval command</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Conditional-searching-using-eval-command/m-p/260979#M78311</link>
      <description>&lt;P&gt;All, &lt;/P&gt;

&lt;P&gt;I have the search below which is using eval and IF statement. I only want one of the search conditions to execute every time this search is called using the &lt;CODE&gt;$LOB$&lt;/CODE&gt; variable. It appears the logic is correct and seems like other ppl have gotten this type of search to work, but the below does not work.&lt;/P&gt;

&lt;P&gt;To simplify my question, here is the logic &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| eval IF "(condition)",then, "Search1", else, "Search2" 
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Any help on why this may not work??&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| eval (newLOB1=if(($LOB$ != "*"), 

"([search index=aws-ec2inventory | fields - _raw | table accountName, instanceId,PrivateIPAddress | dedup instanceId  | eval (newLOB=(replace("$LOB$","COF-","")) |where accountName=newLOB | stats count])"),

"([search index=aws-ec2inventory | fields - _raw | table accountName, instanceId,PrivateIPAddress | dedup instanceId | search accountName=* | stats count])"))
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 02 Feb 2016 14:24:14 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Conditional-searching-using-eval-command/m-p/260979#M78311</guid>
      <dc:creator>karthik40us</dc:creator>
      <dc:date>2016-02-02T14:24:14Z</dc:date>
    </item>
    <item>
      <title>Re: Conditional searching using eval command</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Conditional-searching-using-eval-command/m-p/260980#M78312</link>
      <description>&lt;P&gt;Hi, your query is a bit confusing.&lt;BR /&gt;
Can you review and edit your question but using the Code Sample button (select your code then press the button with 1s and 0s) for your query in order to make sure no especial characters are omitted?&lt;/P&gt;

&lt;P&gt;Thanks,&lt;BR /&gt;
J&lt;/P&gt;</description>
      <pubDate>Tue, 02 Feb 2016 14:36:16 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Conditional-searching-using-eval-command/m-p/260980#M78312</guid>
      <dc:creator>javiergn</dc:creator>
      <dc:date>2016-02-02T14:36:16Z</dc:date>
    </item>
    <item>
      <title>Re: Conditional searching using eval command</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Conditional-searching-using-eval-command/m-p/260981#M78313</link>
      <description>&lt;P&gt;thanks..just reposted&lt;/P&gt;</description>
      <pubDate>Tue, 02 Feb 2016 14:42:33 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Conditional-searching-using-eval-command/m-p/260981#M78313</guid>
      <dc:creator>karthik40us</dc:creator>
      <dc:date>2016-02-02T14:42:33Z</dc:date>
    </item>
    <item>
      <title>Re: Conditional searching using eval command</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Conditional-searching-using-eval-command/m-p/260982#M78314</link>
      <description>&lt;P&gt;Hi, I'm afraid that's not the way conditionals work in Splunk.&lt;/P&gt;

&lt;P&gt;This is what I would do instead:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=aws-ec2inventory 
| fields accountName, instanceId, PrivateIPAddress, "$LOB$"
| dedup instanceId 
| eval newLOB = if("$LOB$" != "*", replace("$LOB$", "COF-", ""),"%")
| where accountName=newLOB 
| stats count
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;In principle that's the equivalent of your query but I'm still not sure about the following:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;newLOB1=if(($LOB$ != "*")
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;What are you trying to achieve there? Is $LOB$ a token in your dashboard?&lt;/P&gt;

&lt;P&gt;Hope that helps,&lt;BR /&gt;
J&lt;/P&gt;</description>
      <pubDate>Tue, 02 Feb 2016 15:00:07 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Conditional-searching-using-eval-command/m-p/260982#M78314</guid>
      <dc:creator>javiergn</dc:creator>
      <dc:date>2016-02-02T15:00:07Z</dc:date>
    </item>
    <item>
      <title>Re: Conditional searching using eval command</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Conditional-searching-using-eval-command/m-p/260983#M78315</link>
      <description>&lt;P&gt;Thanks for the response !!.. you query worked only in cases where LOB !=" **" . If the variable LOB had * the results are 0. Any thoughts?. The below came back with 0 results &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=aws-ec2inventory 
 | fields accountName, instanceId, PrivateIPAddress, "*"
 | dedup instanceId 
 | eval newLOB = if("*" != "*", replace("*", "COF-", ""),"%")
 | where accountName=newLOB 
 | stats count
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 02 Feb 2016 15:52:42 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Conditional-searching-using-eval-command/m-p/260983#M78315</guid>
      <dc:creator>karthik40us</dc:creator>
      <dc:date>2016-02-02T15:52:42Z</dc:date>
    </item>
    <item>
      <title>Re: Conditional searching using eval command</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Conditional-searching-using-eval-command/m-p/260984#M78316</link>
      <description>&lt;P&gt;it almost feels like IF statement does not like "star" **&lt;/P&gt;</description>
      <pubDate>Tue, 02 Feb 2016 15:54:42 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Conditional-searching-using-eval-command/m-p/260984#M78316</guid>
      <dc:creator>karthik40us</dc:creator>
      <dc:date>2016-02-02T15:54:42Z</dc:date>
    </item>
    <item>
      <title>Re: Conditional searching using eval command</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Conditional-searching-using-eval-command/m-p/260985#M78317</link>
      <description>&lt;P&gt;Also it worked for "**" if i removed the below  line from the code&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| where accountName=newLOB 
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 02 Feb 2016 16:10:10 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Conditional-searching-using-eval-command/m-p/260985#M78317</guid>
      <dc:creator>karthik40us</dc:creator>
      <dc:date>2016-02-02T16:10:10Z</dc:date>
    </item>
    <item>
      <title>Re: Conditional searching using eval command</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Conditional-searching-using-eval-command/m-p/260986#M78318</link>
      <description>&lt;P&gt;Hi, I'm now even more confused about what you are trying to do with the LOB variable. * is a wildcard that matches any character but it won't work as that in a where, because it works like an SQL where and you have to use percentage (%) instead.&lt;/P&gt;

&lt;P&gt;So, can you give me an example with two simple tables about what you are trying to achieve so that I can understand a bit better?&lt;/P&gt;

&lt;P&gt;This line here is killing my eyes &lt;span class="lia-unicode-emoji" title=":grinning_face_with_smiling_eyes:"&gt;😄&lt;/span&gt;&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| eval newLOB = if("*" != "*", replace("*", "COF-", ""),"%")
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 02 Feb 2016 16:31:34 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Conditional-searching-using-eval-command/m-p/260986#M78318</guid>
      <dc:creator>javiergn</dc:creator>
      <dc:date>2016-02-02T16:31:34Z</dc:date>
    </item>
    <item>
      <title>Re: Conditional searching using eval command</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Conditional-searching-using-eval-command/m-p/260987#M78319</link>
      <description>&lt;P&gt;By the way, if you just want to check whether a field is null or not you can use the isnull or isnotnull functions as part of your eval.&lt;/P&gt;</description>
      <pubDate>Tue, 02 Feb 2016 16:33:12 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Conditional-searching-using-eval-command/m-p/260987#M78319</guid>
      <dc:creator>javiergn</dc:creator>
      <dc:date>2016-02-02T16:33:12Z</dc:date>
    </item>
    <item>
      <title>Re: Conditional searching using eval command</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Conditional-searching-using-eval-command/m-p/260988#M78320</link>
      <description>&lt;P&gt;The goal is to do a count on $LOB$ (i.e account Name) within aws-ec2inventory index .&lt;/P&gt;

&lt;P&gt;I am getting $LOB$(i.e account name)  as dropdown box from a dashboard panel &lt;/P&gt;

&lt;P&gt;If the $LOB$ is a ** (wildcard) then i need to provide a stats count on ALL  &lt;/P&gt;

&lt;P&gt;If the $LOB$ is not a ** then i am performing a replace function and providing a count for that particular account Name/$LOB$ &lt;/P&gt;

&lt;P&gt;table&lt;/P&gt;

&lt;P&gt;LOB (dropdown input from dashboard)&lt;BR /&gt;
All  ----&amp;gt; (the value for this * )&lt;BR /&gt;
COF-abcd-prod&lt;BR /&gt;
COF-efgh-Dev&lt;BR /&gt;
COF-njkd-Prod&lt;/P&gt;</description>
      <pubDate>Tue, 02 Feb 2016 17:17:51 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Conditional-searching-using-eval-command/m-p/260988#M78320</guid>
      <dc:creator>karthik40us</dc:creator>
      <dc:date>2016-02-02T17:17:51Z</dc:date>
    </item>
    <item>
      <title>Re: Conditional searching using eval command</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Conditional-searching-using-eval-command/m-p/260989#M78321</link>
      <description>&lt;P&gt;Figured it out ..it was the where clause that was the issue and used LIKE instead...thanks for your help&lt;/P&gt;</description>
      <pubDate>Tue, 02 Feb 2016 22:09:29 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Conditional-searching-using-eval-command/m-p/260989#M78321</guid>
      <dc:creator>karthik40us</dc:creator>
      <dc:date>2016-02-02T22:09:29Z</dc:date>
    </item>
  </channel>
</rss>

