<?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: How do I compare two tables based on a logic? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-do-I-compare-two-tables-based-on-a-logic/m-p/607995#M211405</link>
    <description>&lt;P&gt;Given how Splunk search usually work, I suspect that you do not have type1:type2, platform1:platform2, etc. from raw output. &amp;nbsp;Instead, you probably have a type field that can be X or Z, a platform field that can be None, WIN, or LINUX, etc., depending on how search is done. &amp;nbsp;Even if you have type1:type2, etc., you can probably make a search that turn them into a uniform set of fields. &amp;nbsp;This way, you don't have to use low-performance commands like join.&lt;/P&gt;&lt;P&gt;When you have that, what you describe can mostly be delivered with stats commands. &amp;nbsp;Here's a prototype&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;type IN (X, Z) ``` magical raw search ```
| stats values(type) as type by target platform
| eval match = if(mvcount(type) &amp;gt; 1, "yes", null())
| stats values(*) as * by target
| eval match = if(mvcount(platform) &amp;gt; 2, "yes", match)
| eventstats dc(target) as total_match by match
| stats dc(target) as targets_by_type values(total_match) as total_match by type
| eventstats sum(targets_by_type) as total_targets&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The first line is pseudo code for that magical raw search that will return type, platform, and target. &amp;nbsp;Sample output could be&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;type&lt;/TD&gt;&lt;TD&gt;targets_by_type&lt;/TD&gt;&lt;TD&gt;total_match&lt;/TD&gt;&lt;TD&gt;total_targets&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;X&lt;/TD&gt;&lt;TD&gt;4&lt;/TD&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;TD&gt;6&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;Z&lt;/TD&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;TD&gt;6&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;Obviously if you really want total miss, just subtract total_match from total_targets.&lt;/P&gt;&lt;P&gt;The above output is derived from simulated input like the following&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD width="55.8125px" height="25px"&gt;platform&lt;/TD&gt;&lt;TD width="78.09375px" height="25px"&gt;target&lt;/TD&gt;&lt;TD width="43.40625px" height="25px"&gt;type&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD width="55.8125px" height="25px"&gt;WIN&lt;/TD&gt;&lt;TD width="78.09375px" height="25px"&gt;path/cpp&lt;/TD&gt;&lt;TD width="43.40625px" height="25px"&gt;X&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD width="55.8125px" height="25px"&gt;None&lt;/TD&gt;&lt;TD width="78.09375px" height="25px"&gt;path/c&lt;/TD&gt;&lt;TD width="43.40625px" height="25px"&gt;X&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD width="55.8125px" height="25px"&gt;LINUX&lt;/TD&gt;&lt;TD width="78.09375px" height="25px"&gt;path/py&lt;/TD&gt;&lt;TD width="43.40625px" height="25px"&gt;X&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD width="55.8125px" height="25px"&gt;None&lt;/TD&gt;&lt;TD width="78.09375px" height="25px"&gt;path/e&lt;/TD&gt;&lt;TD width="43.40625px" height="25px"&gt;X&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD width="55.8125px" height="25px"&gt;WIN&lt;/TD&gt;&lt;TD width="78.09375px" height="25px"&gt;path/c&lt;/TD&gt;&lt;TD width="43.40625px" height="25px"&gt;Z&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD width="55.8125px" height="25px"&gt;Linux&lt;/TD&gt;&lt;TD width="78.09375px" height="25px"&gt;path/c&lt;/TD&gt;&lt;TD width="43.40625px" height="25px"&gt;Z&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD width="55.8125px" height="25px"&gt;WIN&lt;/TD&gt;&lt;TD width="78.09375px" height="25px"&gt;path/cpp&lt;/TD&gt;&lt;TD width="43.40625px" height="25px"&gt;Z&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD width="55.8125px" height="25px"&gt;LINUX&lt;/TD&gt;&lt;TD width="78.09375px" height="25px"&gt;path/cpp&lt;/TD&gt;&lt;TD width="43.40625px" height="25px"&gt;Z&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;Here is the code used to simulate data&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| makeresults
| eval _raw="type	platform	target
X	WIN	path/cpp
X	None	path/c
X	LINUX	path/py
X	None	path/e
Z	WIN	path/c
Z	Linux	path/c
Z	WIN	path/cpp
Z	LINUX	path/cpp"
| multikv forceheader=1&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 03 Aug 2022 05:43:12 GMT</pubDate>
    <dc:creator>yuanliu</dc:creator>
    <dc:date>2022-08-03T05:43:12Z</dc:date>
    <item>
      <title>How do I compare two tables based on a logic?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-I-compare-two-tables-based-on-a-logic/m-p/607960#M211391</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;I have two search queries which results in table as follow:&lt;/P&gt;
&lt;P class="lia-align-left"&gt;| search query1&lt;/P&gt;
&lt;P class="lia-align-left"&gt;|&amp;nbsp;table type1 platform1 target1&lt;/P&gt;
&lt;TABLE border="1" width="100%"&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD width="33.333333333333336%" height="25px"&gt;type1&lt;/TD&gt;
&lt;TD width="33.333333333333336%" height="25px"&gt;platform1&lt;/TD&gt;
&lt;TD width="33.333333333333336%" height="25px"&gt;target1&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="33.333333333333336%" height="25px"&gt;X&lt;/TD&gt;
&lt;TD width="33.333333333333336%" height="25px"&gt;WIN&lt;/TD&gt;
&lt;TD width="33.333333333333336%" height="25px"&gt;path/cpp&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="33.333333333333336%"&gt;X&lt;/TD&gt;
&lt;TD width="33.333333333333336%"&gt;None&lt;/TD&gt;
&lt;TD width="33.333333333333336%"&gt;path/c&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="33.333333333333336%" height="25px"&gt;X&lt;/TD&gt;
&lt;TD width="33.333333333333336%" height="25px"&gt;LINUX&lt;/TD&gt;
&lt;TD width="33.333333333333336%" height="25px"&gt;path/py&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;| search query2&lt;/P&gt;
&lt;P&gt;|&amp;nbsp;table type2 platform2 target2&lt;/P&gt;
&lt;TABLE border="1" width="100%"&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD width="33.333333333333336%"&gt;type2&lt;/TD&gt;
&lt;TD width="33.333333333333336%"&gt;platform2&lt;/TD&gt;
&lt;TD width="33.333333333333336%"&gt;target2&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="33.333333333333336%"&gt;Z&lt;/TD&gt;
&lt;TD width="33.333333333333336%"&gt;WIN&lt;/TD&gt;
&lt;TD width="33.333333333333336%"&gt;path/cpp&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="33.333333333333336%"&gt;Z&lt;/TD&gt;
&lt;TD width="33.333333333333336%"&gt;LINUX&lt;/TD&gt;
&lt;TD width="33.333333333333336%"&gt;path/cpp&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;(Target are unique based on their full path)&lt;/P&gt;
&lt;P&gt;How I can compare both tables . by making left join between both tables and comparing, such that :&lt;/P&gt;
&lt;P&gt;-&amp;gt; join both tables where first query table is the lead when comparing against, left join I believe ?&lt;/P&gt;
&lt;P&gt;-&amp;gt; Count as match only IF target from first query where&amp;nbsp;platform =&amp;nbsp;WIN , exists in second table where&amp;nbsp;platform =&amp;nbsp;WIN&amp;nbsp;&lt;/P&gt;
&lt;P&gt;-&amp;gt; Count as match only IF target from first query where&amp;nbsp;platform =&amp;nbsp;LINUX, exists in second table where platform = LINUX&lt;/P&gt;
&lt;P&gt;-&amp;gt; Count as match only IF target from first query where&amp;nbsp;platform =&amp;nbsp;NONE, exists&amp;nbsp; in second table for both platform = LINUX and&amp;nbsp;platform = WIN else no match&lt;/P&gt;
&lt;P&gt;Then list results in table with total matching target, total&amp;nbsp; missing target, total target for type X , total target for type Z .&lt;/P&gt;
&lt;P&gt;How I can reach this ?&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 02 Aug 2022 19:33:05 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-I-compare-two-tables-based-on-a-logic/m-p/607960#M211391</guid>
      <dc:creator>ikenahim7</dc:creator>
      <dc:date>2022-08-02T19:33:05Z</dc:date>
    </item>
    <item>
      <title>Re: How do I compare two tables based on a logic?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-I-compare-two-tables-based-on-a-logic/m-p/607974#M211396</link>
      <description>&lt;P&gt;Just substitute the `makeresults` with your actual query.&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| makeresults 
| eval _raw = "type1,platform1,target1
X,WIN,path/cpp
X,None,path/c
X,LINUX,path/py" 
| multikv forceheader=1 
| table type1 platform1 target1 
| join type=inner left=L right=R where L.platform1=R.platform2 L.target1=R.target2 
    [| makeresults 
    | eval _raw = "type2,platform2,target2
Z,WIN,path/cpp
Z,LINUX,path/cpp" 
    | multikv forceheader=1 
    | table type2 platform2 target2 ]
| stats c&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 02 Aug 2022 21:06:25 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-I-compare-two-tables-based-on-a-logic/m-p/607974#M211396</guid>
      <dc:creator>morethanyell</dc:creator>
      <dc:date>2022-08-02T21:06:25Z</dc:date>
    </item>
    <item>
      <title>Re: How do I compare two tables based on a logic?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-I-compare-two-tables-based-on-a-logic/m-p/607995#M211405</link>
      <description>&lt;P&gt;Given how Splunk search usually work, I suspect that you do not have type1:type2, platform1:platform2, etc. from raw output. &amp;nbsp;Instead, you probably have a type field that can be X or Z, a platform field that can be None, WIN, or LINUX, etc., depending on how search is done. &amp;nbsp;Even if you have type1:type2, etc., you can probably make a search that turn them into a uniform set of fields. &amp;nbsp;This way, you don't have to use low-performance commands like join.&lt;/P&gt;&lt;P&gt;When you have that, what you describe can mostly be delivered with stats commands. &amp;nbsp;Here's a prototype&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;type IN (X, Z) ``` magical raw search ```
| stats values(type) as type by target platform
| eval match = if(mvcount(type) &amp;gt; 1, "yes", null())
| stats values(*) as * by target
| eval match = if(mvcount(platform) &amp;gt; 2, "yes", match)
| eventstats dc(target) as total_match by match
| stats dc(target) as targets_by_type values(total_match) as total_match by type
| eventstats sum(targets_by_type) as total_targets&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The first line is pseudo code for that magical raw search that will return type, platform, and target. &amp;nbsp;Sample output could be&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;type&lt;/TD&gt;&lt;TD&gt;targets_by_type&lt;/TD&gt;&lt;TD&gt;total_match&lt;/TD&gt;&lt;TD&gt;total_targets&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;X&lt;/TD&gt;&lt;TD&gt;4&lt;/TD&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;TD&gt;6&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;Z&lt;/TD&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;TD&gt;6&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;Obviously if you really want total miss, just subtract total_match from total_targets.&lt;/P&gt;&lt;P&gt;The above output is derived from simulated input like the following&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD width="55.8125px" height="25px"&gt;platform&lt;/TD&gt;&lt;TD width="78.09375px" height="25px"&gt;target&lt;/TD&gt;&lt;TD width="43.40625px" height="25px"&gt;type&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD width="55.8125px" height="25px"&gt;WIN&lt;/TD&gt;&lt;TD width="78.09375px" height="25px"&gt;path/cpp&lt;/TD&gt;&lt;TD width="43.40625px" height="25px"&gt;X&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD width="55.8125px" height="25px"&gt;None&lt;/TD&gt;&lt;TD width="78.09375px" height="25px"&gt;path/c&lt;/TD&gt;&lt;TD width="43.40625px" height="25px"&gt;X&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD width="55.8125px" height="25px"&gt;LINUX&lt;/TD&gt;&lt;TD width="78.09375px" height="25px"&gt;path/py&lt;/TD&gt;&lt;TD width="43.40625px" height="25px"&gt;X&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD width="55.8125px" height="25px"&gt;None&lt;/TD&gt;&lt;TD width="78.09375px" height="25px"&gt;path/e&lt;/TD&gt;&lt;TD width="43.40625px" height="25px"&gt;X&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD width="55.8125px" height="25px"&gt;WIN&lt;/TD&gt;&lt;TD width="78.09375px" height="25px"&gt;path/c&lt;/TD&gt;&lt;TD width="43.40625px" height="25px"&gt;Z&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD width="55.8125px" height="25px"&gt;Linux&lt;/TD&gt;&lt;TD width="78.09375px" height="25px"&gt;path/c&lt;/TD&gt;&lt;TD width="43.40625px" height="25px"&gt;Z&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD width="55.8125px" height="25px"&gt;WIN&lt;/TD&gt;&lt;TD width="78.09375px" height="25px"&gt;path/cpp&lt;/TD&gt;&lt;TD width="43.40625px" height="25px"&gt;Z&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD width="55.8125px" height="25px"&gt;LINUX&lt;/TD&gt;&lt;TD width="78.09375px" height="25px"&gt;path/cpp&lt;/TD&gt;&lt;TD width="43.40625px" height="25px"&gt;Z&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;Here is the code used to simulate data&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| makeresults
| eval _raw="type	platform	target
X	WIN	path/cpp
X	None	path/c
X	LINUX	path/py
X	None	path/e
Z	WIN	path/c
Z	Linux	path/c
Z	WIN	path/cpp
Z	LINUX	path/cpp"
| multikv forceheader=1&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 03 Aug 2022 05:43:12 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-I-compare-two-tables-based-on-a-logic/m-p/607995#M211405</guid>
      <dc:creator>yuanliu</dc:creator>
      <dc:date>2022-08-03T05:43:12Z</dc:date>
    </item>
    <item>
      <title>Re: How do I compare two tables based on a logic?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-I-compare-two-tables-based-on-a-logic/m-p/608003#M211407</link>
      <description>&lt;P&gt;This wont work, my actual values are move then 30K targets! the tables above was just to explain my logic how i want to compare both queries. each query returns around 12k targets&lt;/P&gt;</description>
      <pubDate>Wed, 03 Aug 2022 06:32:54 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-I-compare-two-tables-based-on-a-logic/m-p/608003#M211407</guid>
      <dc:creator>ikenahim7</dc:creator>
      <dc:date>2022-08-03T06:32:54Z</dc:date>
    </item>
  </channel>
</rss>

