<?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 search command in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Conditional-search-command/m-p/197209#M56957</link>
    <description>&lt;P&gt;Hi Simon,&lt;/P&gt;

&lt;P&gt;I would try something like this, for the &lt;CODE&gt;outputlookup&lt;/CODE&gt; example:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;YourMagicSearchFoo | stats count | where count&amp;gt;0 | YourOtherMagicSearchFoo
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;or for the &lt;CODE&gt;iplocation&lt;/CODE&gt; example:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;YourMagicSearchFoo | where Country=null() | YourOtherMagicSearchFoo
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;hope this helps to get you started ...&lt;/P&gt;

&lt;P&gt;cheers, MuS&lt;/P&gt;</description>
    <pubDate>Tue, 07 Jan 2014 07:51:03 GMT</pubDate>
    <dc:creator>MuS</dc:creator>
    <dc:date>2014-01-07T07:51:03Z</dc:date>
    <item>
      <title>Conditional search command</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Conditional-search-command/m-p/197208#M56956</link>
      <description>&lt;P&gt;Hi Splunkers,&lt;/P&gt;

&lt;P&gt;I was wondering if it's possible to run a search command only under specific conditions?&lt;BR /&gt;
E.g. when a field containts a specific value or when total number of results are at least X.&lt;/P&gt;

&lt;P&gt;Example:&lt;BR /&gt;
I'm running a search which populates a CSV with outputlookup, but I'd only wanted to write the CSV if there we're any search results. &lt;/P&gt;

&lt;P&gt;Other example: &lt;BR /&gt;
Run iplocation only if Country field is empty.&lt;/P&gt;

&lt;P&gt;Thanks,&lt;BR /&gt;
Simon&lt;/P&gt;</description>
      <pubDate>Tue, 07 Jan 2014 07:21:29 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Conditional-search-command/m-p/197208#M56956</guid>
      <dc:creator>Simon</dc:creator>
      <dc:date>2014-01-07T07:21:29Z</dc:date>
    </item>
    <item>
      <title>Re: Conditional search command</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Conditional-search-command/m-p/197209#M56957</link>
      <description>&lt;P&gt;Hi Simon,&lt;/P&gt;

&lt;P&gt;I would try something like this, for the &lt;CODE&gt;outputlookup&lt;/CODE&gt; example:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;YourMagicSearchFoo | stats count | where count&amp;gt;0 | YourOtherMagicSearchFoo
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;or for the &lt;CODE&gt;iplocation&lt;/CODE&gt; example:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;YourMagicSearchFoo | where Country=null() | YourOtherMagicSearchFoo
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;hope this helps to get you started ...&lt;/P&gt;

&lt;P&gt;cheers, MuS&lt;/P&gt;</description>
      <pubDate>Tue, 07 Jan 2014 07:51:03 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Conditional-search-command/m-p/197209#M56957</guid>
      <dc:creator>MuS</dc:creator>
      <dc:date>2014-01-07T07:51:03Z</dc:date>
    </item>
    <item>
      <title>Re: Conditional search command</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Conditional-search-command/m-p/197210#M56958</link>
      <description>&lt;P&gt;Nice suggestion, but in your case, I'll always loose events, which is not exactly what I want.&lt;BR /&gt;
To be more precise:&lt;/P&gt;

&lt;P&gt;Example 1:&lt;BR /&gt;
I wanted to populate the CSV only, if there were any results, but then, I want to write all of them. If there are no results, I want to keep the old CSV.&lt;/P&gt;

&lt;P&gt;Example 2:&lt;BR /&gt;
Maybe the result already contains a Country field. If no, and only in this case, I wanted to run iplocation.&lt;BR /&gt;
The idea is to reduce the amount of iplocation calls.&lt;/P&gt;</description>
      <pubDate>Tue, 07 Jan 2014 07:55:08 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Conditional-search-command/m-p/197210#M56958</guid>
      <dc:creator>Simon</dc:creator>
      <dc:date>2014-01-07T07:55:08Z</dc:date>
    </item>
    <item>
      <title>Re: Conditional search command</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Conditional-search-command/m-p/197211#M56959</link>
      <description>&lt;P&gt;Try following&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;    |multisearch 
    [search &amp;lt;your base search&amp;gt; | where Country=null() | iplocation....] 
    [search &amp;lt;your base search&amp;gt; | where NOT Country=null() ] 
    | &amp;lt;your other search to get result for outputlookup&amp;gt;
    | append  [inputlookup &amp;lt;lookupfilename&amp;gt; | eventstats count as LU_Count] 
    | eventstats count as Total | eval LU_Count=coalesce(LU_Count,Total) | where LU_Count=Total 
    | fields &amp;lt;list of fields to be exported to lookup csv file&amp;gt; 
    | outputlookup &amp;lt;lookupfilename&amp;gt;
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Two subsearches in "|multisearch" will split results from "&lt;YOUR base="" search=""&gt;" to two portion, one with Country=null() and one with Country!=null(). iplocation will be done only for records with Country=null(). &lt;BR /&gt;
Then you append existing data from lookup csv file and LU_Count and Total is calculated.&lt;BR /&gt;
When your search produces result, LU_Count for results from existing  lookup csv file will be less then total and hence will be filtered out (only your base search results are written). If you search produces no result, then result from existing lookup file will be rewritten, hence no data loss.&lt;/YOUR&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 28 Sep 2020 15:36:19 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Conditional-search-command/m-p/197211#M56959</guid>
      <dc:creator>somesoni2</dc:creator>
      <dc:date>2020-09-28T15:36:19Z</dc:date>
    </item>
    <item>
      <title>Re: Conditional search command</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Conditional-search-command/m-p/197212#M56960</link>
      <description>&lt;P&gt;Exactly what I was searching for, perfect! Thank you&lt;/P&gt;</description>
      <pubDate>Wed, 08 Jan 2014 12:07:02 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Conditional-search-command/m-p/197212#M56960</guid>
      <dc:creator>Simon</dc:creator>
      <dc:date>2014-01-08T12:07:02Z</dc:date>
    </item>
  </channel>
</rss>

