<?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: Wildcard expansion in case statement in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Wildcard-expansion-in-case-statement/m-p/97771#M25225</link>
    <description>&lt;P&gt;For the benefit of anyone looking at this, I solved my problem in a completely different way.   I put the entire search string in the pulldown&lt;/P&gt;

&lt;P&gt;&lt;INPUT type="dropdown" token="serverList" /&gt; &lt;BR /&gt;
 &lt;LABEL&gt;Select Environment&lt;/LABEL&gt; &lt;BR /&gt;
   &lt;CHOICE value="host=foobar01 OR host=foobar02 OR host=foobar03"&gt;foobar&lt;/CHOICE&gt; &lt;BR /&gt;
   &lt;CHOICE value="host=barfoo01 OR host=barfoo02 OR host=barfoo03"&gt;barfoo&lt;/CHOICE&gt; &lt;BR /&gt;
&lt;/P&gt;

&lt;P&gt;Then my search string is "source=/var/logs/data.log" | search $serverList$"&lt;/P&gt;

&lt;P&gt;It would be painful for dozens of servers, but I have from 1 to 8 per environment. It's manageable&lt;/P&gt;</description>
    <pubDate>Thu, 09 Aug 2012 18:43:34 GMT</pubDate>
    <dc:creator>clashley</dc:creator>
    <dc:date>2012-08-09T18:43:34Z</dc:date>
    <item>
      <title>Wildcard expansion in case statement</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Wildcard-expansion-in-case-statement/m-p/97763#M25217</link>
      <description>&lt;P&gt;I'll start with what works:   If I do a search&lt;/P&gt;

&lt;P&gt;ERROR host="foobar0*"&lt;/P&gt;

&lt;P&gt;The wildcard(*) expands and I get a list of results with extracted 'host' fields with "foobar01", "foobar02", "foobar03", etc.  This is good.&lt;/P&gt;

&lt;P&gt;Now I want to create a case statement which does this same search as one of the options.   What I'm entering is&lt;/P&gt;

&lt;P&gt;ERROR | eval host=case($env$=1,"foobar0*",$env$=2,"barfoo0*")&lt;/P&gt;

&lt;P&gt;But that doesn't do the same wildcard expansion.   All my host fields are "foobar0*" and I can't tell which actual host they are coming from.   Is there a way to make this wildcard expansion work when it is returned from an 'eval' expression?&lt;/P&gt;</description>
      <pubDate>Mon, 28 Sep 2020 12:04:31 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Wildcard-expansion-in-case-statement/m-p/97763#M25217</guid>
      <dc:creator>clashley</dc:creator>
      <dc:date>2020-09-28T12:04:31Z</dc:date>
    </item>
    <item>
      <title>Re: Wildcard expansion in case statement</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Wildcard-expansion-in-case-statement/m-p/97764#M25218</link>
      <description>&lt;P&gt;The wildcard is supported for the &lt;STRONG&gt;search&lt;/STRONG&gt; command only. The &lt;STRONG&gt;eval&lt;/STRONG&gt; command and the &lt;STRONG&gt;where&lt;/STRONG&gt; command do not support the wildcard -- plus, &lt;STRONG&gt;eval&lt;/STRONG&gt; and &lt;STRONG&gt;where&lt;/STRONG&gt; are case-sensitive. &lt;STRONG&gt;search&lt;/STRONG&gt; is &lt;EM&gt;not&lt;/EM&gt; case-sensitive.&lt;/P&gt;

&lt;P&gt;I suggest that you use the &lt;CODE&gt;match&lt;/CODE&gt; function of &lt;A href="http://docs.splunk.com/Documentation/Splunk/latest/SearchReference/CommonEvalFunctions"&gt;eval&lt;/A&gt; as the conditional argument in the &lt;CODE&gt;case&lt;/CODE&gt; function.&lt;/P&gt;

&lt;P&gt;[Updated to remove paragraph about == vs. = in the case function - they are interchangeable for an equality test.]&lt;/P&gt;

&lt;P&gt;Examples:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;ERROR | eval host=case(x==1,"foobar0",y==2,"barfoo0")

ERROR | eval startsWithX = if(match(host,"^X.*"),"Yes","no")
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;But I don't think I really understand your statement "I want to create a case statement which does this same search as one of the options". A case statement does not do a search - it sets the value of a variable.&lt;/P&gt;

&lt;P&gt;What exactly are you trying to do? A little more context would help.&lt;/P&gt;</description>
      <pubDate>Thu, 12 Jul 2012 22:12:19 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Wildcard-expansion-in-case-statement/m-p/97764#M25218</guid>
      <dc:creator>lguinn2</dc:creator>
      <dc:date>2012-07-12T22:12:19Z</dc:date>
    </item>
    <item>
      <title>Re: Wildcard expansion in case statement</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Wildcard-expansion-in-case-statement/m-p/97765#M25219</link>
      <description>&lt;P&gt;Thank you for your response, I'll try to clear things up - I do not wish to do comparison in my case statement using wildcards. I'm happy to do simple numerical comparison. What I want is to be able to perform two different searches depending on my token $env$.&lt;/P&gt;

&lt;P&gt;So if $env$ is 1, I want to perform the search "ERROR host="foobar0*""&lt;/P&gt;

&lt;P&gt;If $env$ is 2, I want to perform the search "ERROR host="barfoo0*""&lt;/P&gt;

&lt;P&gt;I am trying to accomplish this with a case statement:&lt;/P&gt;

&lt;P&gt;ERROR | eval host=case($env$==1,"foobar0*",$env$==2,"barfoo0*")&lt;/P&gt;

&lt;P&gt;but it is not working&lt;/P&gt;</description>
      <pubDate>Thu, 12 Jul 2012 23:08:22 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Wildcard-expansion-in-case-statement/m-p/97765#M25219</guid>
      <dc:creator>clashley</dc:creator>
      <dc:date>2012-07-12T23:08:22Z</dc:date>
    </item>
    <item>
      <title>Re: Wildcard expansion in case statement</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Wildcard-expansion-in-case-statement/m-p/97766#M25220</link>
      <description>&lt;P&gt;AFAIK, that is not possible in the Splunk GUI. THe Splunk GUI does not recognize environment variables.&lt;/P&gt;

&lt;P&gt;You could write a script that tests the environment variable and then launches the appropriate script, using the Splunk Command Line Interface (CLI).&lt;/P&gt;</description>
      <pubDate>Fri, 13 Jul 2012 18:40:44 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Wildcard-expansion-in-case-statement/m-p/97766#M25220</guid>
      <dc:creator>lguinn2</dc:creator>
      <dc:date>2012-07-13T18:40:44Z</dc:date>
    </item>
    <item>
      <title>Re: Wildcard expansion in case statement</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Wildcard-expansion-in-case-statement/m-p/97767#M25221</link>
      <description>&lt;P&gt;I should be more clear, $env$ is not an environment variable.  It is a token set through an earlier &lt;INPUT /&gt; statement&lt;/P&gt;

&lt;P&gt;&lt;INPUT type="dropdown" token="env" /&gt;&lt;BR /&gt;
 &lt;LABEL&gt;Select Environment&lt;/LABEL&gt;&lt;BR /&gt;
 &lt;CHOICE value="1"&gt;foobar&lt;/CHOICE&gt;&lt;BR /&gt;
 &lt;CHOICE value="2"&gt;barfoo&lt;/CHOICE&gt;&lt;BR /&gt;
&lt;/P&gt;</description>
      <pubDate>Fri, 13 Jul 2012 20:35:09 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Wildcard-expansion-in-case-statement/m-p/97767#M25221</guid>
      <dc:creator>clashley</dc:creator>
      <dc:date>2012-07-13T20:35:09Z</dc:date>
    </item>
    <item>
      <title>Re: Wildcard expansion in case statement</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Wildcard-expansion-in-case-statement/m-p/97768#M25222</link>
      <description>&lt;P&gt;Why not do it this way?&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;&amp;lt;input type="dropdown" token="env"&amp;gt;
 &amp;lt;label&amp;gt;Select Environment&amp;lt;/label&amp;gt;
 &amp;lt;choice value="foobar0*"&amp;gt;foobar&amp;lt;/choice&amp;gt;
 &amp;lt;choice value="barfoo0"&amp;gt;barfoo&amp;lt;/choice&amp;gt;
&amp;lt;/input&amp;gt;
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Then your search should be&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;ERROR host=$env$
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;The chosen value will be substituted; it should work.&lt;/P&gt;

&lt;P&gt;Update: for the example below, where you want to drive multiple searches from a single selection box:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;&amp;lt;input type="dropdown" token="env"&amp;gt;
 &amp;lt;label&amp;gt;Select Environment&amp;lt;/label&amp;gt;
 &amp;lt;choice value="ca"&amp;gt;California&amp;lt;/choice&amp;gt;
 &amp;lt;choice value="fl"&amp;gt;Florida&amp;lt;/choice&amp;gt;
&amp;lt;/input&amp;gt;
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Search 1 is:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;error host="$env$_linux" 
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Search 2 is:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;error host="$env$_solaris" 
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 13 Jul 2012 22:51:23 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Wildcard-expansion-in-case-statement/m-p/97768#M25222</guid>
      <dc:creator>lguinn2</dc:creator>
      <dc:date>2012-07-13T22:51:23Z</dc:date>
    </item>
    <item>
      <title>Re: Wildcard expansion in case statement</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Wildcard-expansion-in-case-statement/m-p/97769#M25223</link>
      <description>&lt;P&gt;That does work, but I want to spawn multiple searches from a single pulldown.   So lets say I have server farms in two states&lt;/P&gt;

&lt;P&gt;&lt;INPUT type="dropdown" token="env" /&gt;&lt;BR /&gt;
 &lt;LABEL&gt;Select Environment&lt;/LABEL&gt;&lt;BR /&gt;
 &lt;CHOICE value="1"&gt;California&lt;/CHOICE&gt;&lt;BR /&gt;
 &lt;CHOICE value="2"&gt;Florida&lt;/CHOICE&gt;&lt;BR /&gt;
&lt;/P&gt;

&lt;P&gt;In one panel I want to show the errors on the linux servers&lt;/P&gt;

&lt;P&gt;ERROR | eval host=case($env$=1,"ca_linux*",$env$=2,"fl_linux*")&lt;/P&gt;

&lt;P&gt;In the next panel, I want to show the errors on the solaris servers&lt;/P&gt;

&lt;P&gt;ERROR | eval host=case($env$=1,"ca_solaris*",$env$=2,"fl_solaris*")&lt;/P&gt;</description>
      <pubDate>Mon, 28 Sep 2020 12:06:12 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Wildcard-expansion-in-case-statement/m-p/97769#M25223</guid>
      <dc:creator>clashley</dc:creator>
      <dc:date>2020-09-28T12:06:12Z</dc:date>
    </item>
    <item>
      <title>Re: Wildcard expansion in case statement</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Wildcard-expansion-in-case-statement/m-p/97770#M25224</link>
      <description>&lt;P&gt;Okay, your case statement might actually assign the value that you want to the host variable, but it doesn't search for hosts that match that value.&lt;/P&gt;

&lt;P&gt;You would have to do something like this instead:&lt;/P&gt;

&lt;P&gt;&lt;CODE&gt;ERROR | eval hostMatch=case($env$=1,"ca_linux",$env$=2,"fl_linux") | where host=hostMatch&lt;/CODE&gt;&lt;/P&gt;

&lt;P&gt;Also see updated answer above.&lt;/P&gt;</description>
      <pubDate>Tue, 17 Jul 2012 06:55:48 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Wildcard-expansion-in-case-statement/m-p/97770#M25224</guid>
      <dc:creator>lguinn2</dc:creator>
      <dc:date>2012-07-17T06:55:48Z</dc:date>
    </item>
    <item>
      <title>Re: Wildcard expansion in case statement</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Wildcard-expansion-in-case-statement/m-p/97771#M25225</link>
      <description>&lt;P&gt;For the benefit of anyone looking at this, I solved my problem in a completely different way.   I put the entire search string in the pulldown&lt;/P&gt;

&lt;P&gt;&lt;INPUT type="dropdown" token="serverList" /&gt; &lt;BR /&gt;
 &lt;LABEL&gt;Select Environment&lt;/LABEL&gt; &lt;BR /&gt;
   &lt;CHOICE value="host=foobar01 OR host=foobar02 OR host=foobar03"&gt;foobar&lt;/CHOICE&gt; &lt;BR /&gt;
   &lt;CHOICE value="host=barfoo01 OR host=barfoo02 OR host=barfoo03"&gt;barfoo&lt;/CHOICE&gt; &lt;BR /&gt;
&lt;/P&gt;

&lt;P&gt;Then my search string is "source=/var/logs/data.log" | search $serverList$"&lt;/P&gt;

&lt;P&gt;It would be painful for dozens of servers, but I have from 1 to 8 per environment. It's manageable&lt;/P&gt;</description>
      <pubDate>Thu, 09 Aug 2012 18:43:34 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Wildcard-expansion-in-case-statement/m-p/97771#M25225</guid>
      <dc:creator>clashley</dc:creator>
      <dc:date>2012-08-09T18:43:34Z</dc:date>
    </item>
    <item>
      <title>Re: Wildcard expansion in case statement</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Wildcard-expansion-in-case-statement/m-p/97772#M25226</link>
      <description>&lt;P&gt;index=main sourcetype=email address= | eval domain=case(address LIKE "%gmail.com", "GMAIL", address LIKE "%yahoo.com", "YAHOO",address LIKE "%hotmail.com","HOTMAIL")* | stats count by domain&lt;/P&gt;

&lt;P&gt;(% is the wildcard)&lt;/P&gt;

&lt;P&gt;From:&lt;BR /&gt;
&lt;A href="https://answers.splunk.com/answers/170602/how-would-i-use-eval-with-a-wildcard-to-create-a-c.html"&gt;https://answers.splunk.com/answers/170602/how-would-i-use-eval-with-a-wildcard-to-create-a-c.html&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 13 Feb 2017 16:41:25 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Wildcard-expansion-in-case-statement/m-p/97772#M25226</guid>
      <dc:creator>stanwin</dc:creator>
      <dc:date>2017-02-13T16:41:25Z</dc:date>
    </item>
  </channel>
</rss>

