<?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: declare a variable in search string in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/declare-a-variable-in-search-string/m-p/81551#M20681</link>
    <description>&lt;P&gt;After declaring the variable will you be able to use Os_Type in calculating other fieldvalues?&lt;/P&gt;</description>
    <pubDate>Mon, 11 Jan 2016 07:57:59 GMT</pubDate>
    <dc:creator>muthvin</dc:creator>
    <dc:date>2016-01-11T07:57:59Z</dc:date>
    <item>
      <title>declare a variable in search string</title>
      <link>https://community.splunk.com/t5/Splunk-Search/declare-a-variable-in-search-string/m-p/81543#M20673</link>
      <description>&lt;P&gt;I have a search string (given below). Now I want to declare a variable named Os_Type, which based on the source type, will provide me OS Type.&lt;/P&gt;

&lt;P&gt;index=os source=Perfmon:LocalLogicalDisk&lt;BR /&gt;
        | where like(counter, "% Free Space")&lt;BR /&gt;
        | stats avg(Value) as "availDiskPct" by host&lt;BR /&gt;
        | eval availDiskPct=round(availDiskPct, 2) &lt;/P&gt;

&lt;P&gt;Now I have tried with &lt;BR /&gt;
eval Os_Type=if($source$=="&lt;EM&gt;:&lt;/EM&gt;","WINDOWS","unix")&lt;BR /&gt;
but it is not giving me the correct result.&lt;/P&gt;

&lt;P&gt;Please help me!!!&lt;/P&gt;</description>
      <pubDate>Tue, 08 Jan 2013 21:49:23 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/declare-a-variable-in-search-string/m-p/81543#M20673</guid>
      <dc:creator>Splunk_U</dc:creator>
      <dc:date>2013-01-08T21:49:23Z</dc:date>
    </item>
    <item>
      <title>Re: declare a variable in search string</title>
      <link>https://community.splunk.com/t5/Splunk-Search/declare-a-variable-in-search-string/m-p/81544#M20674</link>
      <description>&lt;P&gt;You're correct in that you should be using &lt;CODE&gt;eval&lt;/CODE&gt;, but your eval statement looks a bit off. As it is now, "Os_Type" would only get the value "WINDOWS" if the source field is EXACTLY ":". Did you mean that it should CONTAIN ":"? If so, you should do something like&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;... | eval Os_Type=if(match(source,":"),"WINDOWS","unix")
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 08 Jan 2013 22:30:06 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/declare-a-variable-in-search-string/m-p/81544#M20674</guid>
      <dc:creator>Ayn</dc:creator>
      <dc:date>2013-01-08T22:30:06Z</dc:date>
    </item>
    <item>
      <title>Re: declare a variable in search string</title>
      <link>https://community.splunk.com/t5/Splunk-Search/declare-a-variable-in-search-string/m-p/81545#M20675</link>
      <description>&lt;P&gt;I meant that : should be present in the source. I tried with what you have suggested...but it is giving me the wrong result.&lt;/P&gt;</description>
      <pubDate>Wed, 09 Jan 2013 13:54:06 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/declare-a-variable-in-search-string/m-p/81545#M20675</guid>
      <dc:creator>Splunk_U</dc:creator>
      <dc:date>2013-01-09T13:54:06Z</dc:date>
    </item>
    <item>
      <title>Re: declare a variable in search string</title>
      <link>https://community.splunk.com/t5/Splunk-Search/declare-a-variable-in-search-string/m-p/81546#M20676</link>
      <description>&lt;P&gt;even if I am trying to search the below mentioned string:&lt;/P&gt;

&lt;P&gt;index=os source=Perfmon:LocalMainMemory &lt;BR /&gt;
| where like(counter,"% Committed Bytes In Use")&lt;BR /&gt;
| stats avg(Value) as "avgMemPct", max(Value) as "peakMemPct" by host&lt;BR /&gt;
| eval avgMemPct=round(avgMemPct,2)&lt;BR /&gt;
| eval peakMemPct=round(peakMemPct,2)&lt;BR /&gt;
| eval Os_Type=if(source=="Perfmon:LocalMainMemory","WINDOWS","Unix")&lt;/P&gt;

&lt;P&gt;the result is coming as Unix ...is there any problem with the conditional operator..&lt;/P&gt;</description>
      <pubDate>Wed, 09 Jan 2013 16:16:30 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/declare-a-variable-in-search-string/m-p/81546#M20676</guid>
      <dc:creator>Splunk_U</dc:creator>
      <dc:date>2013-01-09T16:16:30Z</dc:date>
    </item>
    <item>
      <title>Re: declare a variable in search string</title>
      <link>https://community.splunk.com/t5/Splunk-Search/declare-a-variable-in-search-string/m-p/81547#M20677</link>
      <description>&lt;P&gt;Ah, I see now - you're putting your &lt;CODE&gt;eval&lt;/CODE&gt; after the &lt;CODE&gt;stats&lt;/CODE&gt; command. The only field output from &lt;CODE&gt;stats&lt;/CODE&gt; will be the fields that it produces - in your case avgMemPct, peakMemPct and host. So, when you're doing your &lt;CODE&gt;eval&lt;/CODE&gt; statement at the end, the &lt;CODE&gt;source&lt;/CODE&gt; field no longer exists. You need to put the &lt;CODE&gt;eval&lt;/CODE&gt; before your &lt;CODE&gt;stats&lt;/CODE&gt; command and then do something like splitting by host AND Os_Type in order to get it to show in your results.&lt;/P&gt;</description>
      <pubDate>Wed, 09 Jan 2013 19:01:42 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/declare-a-variable-in-search-string/m-p/81547#M20677</guid>
      <dc:creator>Ayn</dc:creator>
      <dc:date>2013-01-09T19:01:42Z</dc:date>
    </item>
    <item>
      <title>Re: declare a variable in search string</title>
      <link>https://community.splunk.com/t5/Splunk-Search/declare-a-variable-in-search-string/m-p/81548#M20678</link>
      <description>&lt;P&gt;tried to find how can we use split by...but did not find luck...can you please tell me the syntax for the same?&lt;/P&gt;</description>
      <pubDate>Wed, 09 Jan 2013 19:53:44 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/declare-a-variable-in-search-string/m-p/81548#M20678</guid>
      <dc:creator>Splunk_U</dc:creator>
      <dc:date>2013-01-09T19:53:44Z</dc:date>
    </item>
    <item>
      <title>Re: declare a variable in search string</title>
      <link>https://community.splunk.com/t5/Splunk-Search/declare-a-variable-in-search-string/m-p/81549#M20679</link>
      <description>&lt;P&gt;Something like&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=os source=Perfmon:LocalMainMemory | where like(counter,"% Committed Bytes In Use") | eval Os_Type=if(source=="Perfmon:LocalMainMemory","WINDOWS","Unix") | stats avg(Value) as "avgMemPct", max(Value) as "peakMemPct" by host,Os_Type | eval avgMemPct=round(avgMemPct,2) | eval peakMemPct=round(peakMemPct,2)
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;should do it.&lt;/P&gt;</description>
      <pubDate>Wed, 09 Jan 2013 20:01:37 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/declare-a-variable-in-search-string/m-p/81549#M20679</guid>
      <dc:creator>Ayn</dc:creator>
      <dc:date>2013-01-09T20:01:37Z</dc:date>
    </item>
    <item>
      <title>Re: declare a variable in search string</title>
      <link>https://community.splunk.com/t5/Splunk-Search/declare-a-variable-in-search-string/m-p/81550#M20680</link>
      <description>&lt;P&gt;Thank you!!!&lt;/P&gt;</description>
      <pubDate>Wed, 09 Jan 2013 20:37:37 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/declare-a-variable-in-search-string/m-p/81550#M20680</guid>
      <dc:creator>Splunk_U</dc:creator>
      <dc:date>2013-01-09T20:37:37Z</dc:date>
    </item>
    <item>
      <title>Re: declare a variable in search string</title>
      <link>https://community.splunk.com/t5/Splunk-Search/declare-a-variable-in-search-string/m-p/81551#M20681</link>
      <description>&lt;P&gt;After declaring the variable will you be able to use Os_Type in calculating other fieldvalues?&lt;/P&gt;</description>
      <pubDate>Mon, 11 Jan 2016 07:57:59 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/declare-a-variable-in-search-string/m-p/81551#M20681</guid>
      <dc:creator>muthvin</dc:creator>
      <dc:date>2016-01-11T07:57:59Z</dc:date>
    </item>
  </channel>
</rss>

