<?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: Create a new variable within a search in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Create-a-new-variable-within-a-search/m-p/71353#M17854</link>
    <description>&lt;P&gt;Your welcome, I am glad it worked.&lt;/P&gt;</description>
    <pubDate>Thu, 27 Sep 2012 16:23:25 GMT</pubDate>
    <dc:creator>melting</dc:creator>
    <dc:date>2012-09-27T16:23:25Z</dc:date>
    <item>
      <title>Create a new variable within a search</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Create-a-new-variable-within-a-search/m-p/71348#M17849</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;

&lt;P&gt;I'd like to use the top command in my search. The problem is, that the fields which I want to top can change if the sourcetype change.&lt;/P&gt;

&lt;P&gt;sourcetype=windows than top eventlog&lt;BR /&gt;
sourcetype=others than linux_messages&lt;/P&gt;

&lt;P&gt;My idea was the following&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;sourcetype=windows | eval os = if(sourcetype="windows","eventlog","linux_messages") | top os
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;With "top os" Splunk only displays "eventlog" (as logical). But "eventlog" is also a field. I want that Splunk replace the "top os" to "top eventlog".&lt;/P&gt;

&lt;P&gt;Is there a way to to this?&lt;/P&gt;

&lt;P&gt;Thank you&lt;/P&gt;</description>
      <pubDate>Wed, 26 Sep 2012 11:52:51 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Create-a-new-variable-within-a-search/m-p/71348#M17849</guid>
      <dc:creator>nebel</dc:creator>
      <dc:date>2012-09-26T11:52:51Z</dc:date>
    </item>
    <item>
      <title>Re: Create a new variable within a search</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Create-a-new-variable-within-a-search/m-p/71349#M17850</link>
      <description>&lt;P&gt;What exactly are wanting to do this for? Why does separate searches work for you since the data and fields are different?  &lt;/P&gt;

&lt;P&gt;You could do something like this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;* | eval something = if(sourcetype="windows", eventlog, someotherfield) | top something
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;First you need to remove "sourcetype=windows" because you are only going to get that result when you have already filtered on windows prior to the 'if' statement.  In this case, if it's windows it's going to top the eventlog field for you.  For everything else it's going to choose someotherfield which would need to be common among the other stuff you want to look at.&lt;/P&gt;</description>
      <pubDate>Wed, 26 Sep 2012 12:26:11 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Create-a-new-variable-within-a-search/m-p/71349#M17850</guid>
      <dc:creator>sdaniels</dc:creator>
      <dc:date>2012-09-26T12:26:11Z</dc:date>
    </item>
    <item>
      <title>Re: Create a new variable within a search</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Create-a-new-variable-within-a-search/m-p/71350#M17851</link>
      <description>&lt;P&gt;thanks! But I think we have a misunderstanding.&lt;/P&gt;

&lt;P&gt;I have Windows and Linux logs. I also have one dashboard and on that dashboard I have a drop down to switch between Windows and Linux. &lt;/P&gt;

&lt;P&gt;I see for instance the top Windows/Linux error messages. I wan't to realize this in one search. With a drop down, I choose the sourcetype (windows/linux) but the top command is the problem because the fields in windows and linux are different. In windows it is eventlog and in linux it is messages. The idea was to populate the top command by a if command which recognize which sourcetype is choosed...&lt;/P&gt;</description>
      <pubDate>Wed, 26 Sep 2012 12:39:00 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Create-a-new-variable-within-a-search/m-p/71350#M17851</guid>
      <dc:creator>nebel</dc:creator>
      <dc:date>2012-09-26T12:39:00Z</dc:date>
    </item>
    <item>
      <title>Re: Create a new variable within a search</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Create-a-new-variable-within-a-search/m-p/71351#M17852</link>
      <description>&lt;P&gt;I have used macros in the past to help with this.  You could use the stringreplace to pick which macro to use.&lt;/P&gt;

&lt;P&gt;So you would have at least two search macros. &lt;CODE&gt;oslogs-windows&lt;/CODE&gt; and &lt;CODE&gt;oslogs-linux&lt;/CODE&gt;&lt;/P&gt;

&lt;P&gt;In the search you can refer to them like &lt;BR /&gt;
    .... | &lt;CODE&gt;oslogs-$os$&lt;/CODE&gt;&lt;BR /&gt;
so when os is linux it will use the &lt;CODE&gt;oslogs-linux macro, and when windows it uses the&lt;/CODE&gt;oslogs-windows` macro&lt;/P&gt;</description>
      <pubDate>Wed, 26 Sep 2012 16:42:20 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Create-a-new-variable-within-a-search/m-p/71351#M17852</guid>
      <dc:creator>melting</dc:creator>
      <dc:date>2012-09-26T16:42:20Z</dc:date>
    </item>
    <item>
      <title>Re: Create a new variable within a search</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Create-a-new-variable-within-a-search/m-p/71352#M17853</link>
      <description>&lt;P&gt;I am really thankful for your answer! worked great &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 27 Sep 2012 08:16:51 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Create-a-new-variable-within-a-search/m-p/71352#M17853</guid>
      <dc:creator>nebel</dc:creator>
      <dc:date>2012-09-27T08:16:51Z</dc:date>
    </item>
    <item>
      <title>Re: Create a new variable within a search</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Create-a-new-variable-within-a-search/m-p/71353#M17854</link>
      <description>&lt;P&gt;Your welcome, I am glad it worked.&lt;/P&gt;</description>
      <pubDate>Thu, 27 Sep 2012 16:23:25 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Create-a-new-variable-within-a-search/m-p/71353#M17854</guid>
      <dc:creator>melting</dc:creator>
      <dc:date>2012-09-27T16:23:25Z</dc:date>
    </item>
  </channel>
</rss>

