<?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: Subtract one search from another based on time of searches in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Subtract-one-search-from-another-based-on-time-of-searches/m-p/174409#M50048</link>
    <description>&lt;P&gt;That worked perfectly!  Thanks for your excellent help.&lt;/P&gt;</description>
    <pubDate>Wed, 11 Dec 2013 11:17:50 GMT</pubDate>
    <dc:creator>leatherface</dc:creator>
    <dc:date>2013-12-11T11:17:50Z</dc:date>
    <item>
      <title>Subtract one search from another based on time of searches</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Subtract-one-search-from-another-based-on-time-of-searches/m-p/174407#M50046</link>
      <description>&lt;P&gt;I'm looking to get a list of results of events that should have occured in the last day by running a search with the date range &lt;CODE&gt;earliest=-7d@d latest=-24h&lt;/CODE&gt; then running the same search for the range &lt;CODE&gt;earliest=-24h&lt;/CODE&gt;, then subtracting the second result from the first to tell me what events happened over the last week but not in the last 24 hours.&lt;BR /&gt;
The best I could come up with was to write the results the last 24 hours to a file using &lt;CODE&gt;outputlookup&lt;/CODE&gt;:&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;
&lt;CODE&gt;index="theindex" earliest=-24h  | stats count by theevent| eval seen="yes" | outputlookup lastday.csv&lt;/CODE&gt;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;
 then run a second query that looked back a week&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;
&lt;CODE&gt;index="theindex" earliest=-7d@d latest=-24h  | stats count by theevent| lookup lastday.csv theevent OUTPUT seen | where NOT seen="yes"&lt;/CODE&gt;&lt;/P&gt;

&lt;P&gt;Is there a better way to do this?  A single search would make me very happy!&lt;BR /&gt;
Thanks in advance&lt;/P&gt;</description>
      <pubDate>Wed, 11 Dec 2013 00:27:22 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Subtract-one-search-from-another-based-on-time-of-searches/m-p/174407#M50046</guid>
      <dc:creator>leatherface</dc:creator>
      <dc:date>2013-12-11T00:27:22Z</dc:date>
    </item>
    <item>
      <title>Re: Subtract one search from another based on time of searches</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Subtract-one-search-from-another-based-on-time-of-searches/m-p/174408#M50047</link>
      <description>&lt;P&gt;Absolutely, you can do this in a single search. It's all about stitching it together. Essentially you can follow the steps here, but adapt it to your needs.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=theindex earliest=-7d latest=-24h theevent=* NOT [search index=theindex earliest=-24h theevent=* | dedup theevent | fields + theevent] | stats c by theevent
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;The resulting table will contain the events that occurred in the last week, but not in the last 24 hours.&lt;/P&gt;

&lt;P&gt;The inner search (in square brackets) will get executed first and produce a (deduplicated) list of 'theevent', which are appended with a NOT to the outer search. Then you do your stats count.&lt;/P&gt;

&lt;P&gt;You may even do it in a single search without subsearches, but maybe it won't be more efficient;&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=theindex earliest=-7d theevent=* | eval AAA = if(_time &amp;lt; (now() - 86400), "last_week", "today") | dedup theevent AAA | transaction theevent max_events=2| where eventcount=1 AND AAA="last_week"   
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;... I think, haven't tested the last one. But it - or something very close - will work as well.&lt;/P&gt;

&lt;P&gt;/k&lt;/P&gt;</description>
      <pubDate>Wed, 11 Dec 2013 01:33:05 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Subtract-one-search-from-another-based-on-time-of-searches/m-p/174408#M50047</guid>
      <dc:creator>kristian_kolb</dc:creator>
      <dc:date>2013-12-11T01:33:05Z</dc:date>
    </item>
    <item>
      <title>Re: Subtract one search from another based on time of searches</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Subtract-one-search-from-another-based-on-time-of-searches/m-p/174409#M50048</link>
      <description>&lt;P&gt;That worked perfectly!  Thanks for your excellent help.&lt;/P&gt;</description>
      <pubDate>Wed, 11 Dec 2013 11:17:50 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Subtract-one-search-from-another-based-on-time-of-searches/m-p/174409#M50048</guid>
      <dc:creator>leatherface</dc:creator>
      <dc:date>2013-12-11T11:17:50Z</dc:date>
    </item>
  </channel>
</rss>

