<?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 find the unique elements between two columns? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-do-I-find-the-unique-elements-between-two-columns/m-p/248661#M74266</link>
    <description>&lt;P&gt;Try this&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt; search key=* | stats values(stuff) as M by key | sort M | 
      join type=left key [ search key=* | stats values(otherstuff)  as N | sort N ] 
     | eval merged=mvappend(M, N) 
     | eval unique=mvdedup(merged)
&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Sat, 15 Oct 2016 00:12:27 GMT</pubDate>
    <dc:creator>sundareshr</dc:creator>
    <dc:date>2016-10-15T00:12:27Z</dc:date>
    <item>
      <title>How do I find the unique elements between two columns?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-I-find-the-unique-elements-between-two-columns/m-p/248660#M74265</link>
      <description>&lt;P&gt;If I have a search that returns a table with multi-values in two different columns, how can I find the unique elements in one column vs the other?&lt;/P&gt;

&lt;P&gt;For example, if my results returns colA and colB I want to add a result column "result" as follows:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;key       colA             colB         Result
1     dog cat bird       dog bird        cat
2     red green blue     green blue      red
3     ford chevy dodge   ford chevy     dodge
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;For what it's worth, colA and colB are the results of two searches and the table is a join, like so:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;search key=* | stats values(stuff) as M by key | sort M | 
     join type=left key [ search key=* | stats values(otherstuff)  as N | sort N ]
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 14 Oct 2016 23:24:40 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-I-find-the-unique-elements-between-two-columns/m-p/248660#M74265</guid>
      <dc:creator>mbintz</dc:creator>
      <dc:date>2016-10-14T23:24:40Z</dc:date>
    </item>
    <item>
      <title>Re: How do I find the unique elements between two columns?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-I-find-the-unique-elements-between-two-columns/m-p/248661#M74266</link>
      <description>&lt;P&gt;Try this&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt; search key=* | stats values(stuff) as M by key | sort M | 
      join type=left key [ search key=* | stats values(otherstuff)  as N | sort N ] 
     | eval merged=mvappend(M, N) 
     | eval unique=mvdedup(merged)
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 15 Oct 2016 00:12:27 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-I-find-the-unique-elements-between-two-columns/m-p/248661#M74266</guid>
      <dc:creator>sundareshr</dc:creator>
      <dc:date>2016-10-15T00:12:27Z</dc:date>
    </item>
    <item>
      <title>Re: How do I find the unique elements between two columns?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-I-find-the-unique-elements-between-two-columns/m-p/248662#M74267</link>
      <description>&lt;P&gt;Whenever I work with mv fields, I always feel like I'm going out of my way to get where I'm headed, but this seems to work with some very basic test data...&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;... | eval tmp = split(mvjoin(mvzip(colA,colB),","),",") 
| mvexpand tmp 
| eventstats count by key tmp 
| eval result = if(count=1,tmp,"") 
| fields - count tmp 
| mvcombine result
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;OL&gt;
&lt;LI&gt;&lt;P&gt;So I start by putting colA and colB togehter in one field and then use join/split to ultimately get each value from both fields in one mv field, dups included.  &lt;/P&gt;&lt;/LI&gt;
&lt;LI&gt;&lt;P&gt;Then I use mvexpand to create one event for each of those values.  &lt;/P&gt;&lt;/LI&gt;
&lt;LI&gt;&lt;P&gt;Now I can use eventstats to count how many of each value exist for each key.  &lt;/P&gt;&lt;/LI&gt;
&lt;LI&gt;&lt;P&gt;Then create a new result field that contains the value if there is only one of them (so it only exists in one of the lists), or just an empty string if greater than one.  &lt;/P&gt;&lt;/LI&gt;
&lt;LI&gt;&lt;P&gt;Finally, get rid some of those unneeded field I created and combine the events back together based on the result field.&lt;/P&gt;&lt;/LI&gt;
&lt;/OL&gt;

&lt;P&gt;Side note, not sure if your search/data is more complicated than it looks, but are you sure you need to be doing a join?  Any reason you can't just do &lt;CODE&gt;stats values(stuff) as M values(otherStuff) as N by key&lt;/CODE&gt;&lt;/P&gt;</description>
      <pubDate>Sat, 15 Oct 2016 00:15:34 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-I-find-the-unique-elements-between-two-columns/m-p/248662#M74267</guid>
      <dc:creator>maciep</dc:creator>
      <dc:date>2016-10-15T00:15:34Z</dc:date>
    </item>
    <item>
      <title>Re: How do I find the unique elements between two columns?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-I-find-the-unique-elements-between-two-columns/m-p/248663#M74268</link>
      <description>&lt;P&gt;This works if I replace &lt;CODE&gt;| eval tmp = split(mvjoin(mvzip(colA,colB),","),",")&lt;/CODE&gt; with &lt;CODE&gt;| eval tmp = mvappend(colA,colB)&lt;/CODE&gt; .&lt;/P&gt;</description>
      <pubDate>Sat, 15 Oct 2016 04:07:05 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-I-find-the-unique-elements-between-two-columns/m-p/248663#M74268</guid>
      <dc:creator>somesoni2</dc:creator>
      <dc:date>2016-10-15T04:07:05Z</dc:date>
    </item>
    <item>
      <title>Re: How do I find the unique elements between two columns?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-I-find-the-unique-elements-between-two-columns/m-p/248664#M74269</link>
      <description>&lt;P&gt;I downvoted this post because this is just a dedup'ed union.  i'm looking for the elements on cola that are not in colb.&lt;/P&gt;</description>
      <pubDate>Sat, 15 Oct 2016 18:18:11 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-I-find-the-unique-elements-between-two-columns/m-p/248664#M74269</guid>
      <dc:creator>mbintz</dc:creator>
      <dc:date>2016-10-15T18:18:11Z</dc:date>
    </item>
    <item>
      <title>Re: How do I find the unique elements between two columns?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-I-find-the-unique-elements-between-two-columns/m-p/248665#M74270</link>
      <description>&lt;P&gt;I had to make a few more tweaks.  Because the initial search is doing stats on each set of results, the output of the search (and thus the join) is not a "stream" but a stats table.  Despite my belief that my columns were already multi-values, they were not (apparently) and I had to split them.  Because it was table, streamstats didn't work.  A simple switch to "stats" did the trick, &lt;/P&gt;

&lt;P&gt;So the final answer is:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;... | eval tmp = mvappend(split(colA, " "), split(colB, " "))
| stats count by key,tmp
| eval result=if(count=1,tmp,"")
| fields - count tmp
mvcombine result
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 15 Oct 2016 18:25:36 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-I-find-the-unique-elements-between-two-columns/m-p/248665#M74270</guid>
      <dc:creator>mbintz</dc:creator>
      <dc:date>2016-10-15T18:25:36Z</dc:date>
    </item>
  </channel>
</rss>

