<?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 edit my current search to compare the values of 2 fields efficiently? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-do-I-edit-my-current-search-to-compare-the-values-of-2/m-p/236535#M70267</link>
    <description>&lt;P&gt;Try something like this. This is inline with your expected output&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=1 OR index=2 | eval common=coalesce(field1,field2) | stats values(index) as index by common | eval Field1=case(mvcount(index)=2,common, mvcount(index)=1 AND index="1",common,1=1,"") | eval Field2=case(mvcount(index)=2,common, mvcount(index)=1 AND index="2",common,1=1,"") | table Field1 Field2
&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Tue, 19 Jan 2016 15:12:23 GMT</pubDate>
    <dc:creator>somesoni2</dc:creator>
    <dc:date>2016-01-19T15:12:23Z</dc:date>
    <item>
      <title>How do I edit my current search to compare the values of 2 fields efficiently?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-I-edit-my-current-search-to-compare-the-values-of-2/m-p/236531#M70263</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;

&lt;P&gt;I want to compare results of 2 searches, I am using a subsearch and a join&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=1 | table field1 | eval a=field1| join type=left a [ | search index=2 |table field2 | eval a=field2 | fields -a 
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Problem is that field2 doesn´t have all the values of field1 and I want to check which values are present and if they are equal.&lt;/P&gt;

&lt;P&gt;Should look like that:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;Field1   Field2
value1   value1
vaule2   value2
vaule3
vuale4   value4
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;For now I just got it work by comparing both fields with the new field a. Is there a way to get that done more efficiently?&lt;/P&gt;

&lt;P&gt;Thank you&lt;/P&gt;</description>
      <pubDate>Tue, 19 Jan 2016 13:29:35 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-I-edit-my-current-search-to-compare-the-values-of-2/m-p/236531#M70263</guid>
      <dc:creator>dkeck</dc:creator>
      <dc:date>2016-01-19T13:29:35Z</dc:date>
    </item>
    <item>
      <title>Re: How do I edit my current search to compare the values of 2 fields efficiently?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-I-edit-my-current-search-to-compare-the-values-of-2/m-p/236532#M70264</link>
      <description>&lt;P&gt;if you want something more efficient then get rid of the join. I'm still not 100% sure what you are trying to achieve anyway, can you explain with some data?&lt;/P&gt;

&lt;P&gt;In any case, try the following query (NOT TESTED) and let me know:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt; index=1 OR index=2
| eval newfield = coalesce(field1,field2)
| stats first(field1) as field1, first(field2) as field2 by newfield
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;newfield is the equivalent of a uniqueID in your join&lt;/P&gt;

&lt;P&gt;If the above doesn't work for you please post a more detailed example of how your data looks like.&lt;/P&gt;

&lt;P&gt;Thanks,&lt;BR /&gt;
J&lt;/P&gt;</description>
      <pubDate>Tue, 19 Jan 2016 14:10:35 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-I-edit-my-current-search-to-compare-the-values-of-2/m-p/236532#M70264</guid>
      <dc:creator>javiergn</dc:creator>
      <dc:date>2016-01-19T14:10:35Z</dc:date>
    </item>
    <item>
      <title>Re: How do I edit my current search to compare the values of 2 fields efficiently?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-I-edit-my-current-search-to-compare-the-values-of-2/m-p/236533#M70265</link>
      <description>&lt;P&gt;try like this :&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;(index=ind1 OR index=ind2) | table field1 field2 | eval field2=if(field1=field2, field1,"")
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 19 Jan 2016 14:15:59 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-I-edit-my-current-search-to-compare-the-values-of-2/m-p/236533#M70265</guid>
      <dc:creator>fdi01</dc:creator>
      <dc:date>2016-01-19T14:15:59Z</dc:date>
    </item>
    <item>
      <title>Re: How do I edit my current search to compare the values of 2 fields efficiently?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-I-edit-my-current-search-to-compare-the-values-of-2/m-p/236534#M70266</link>
      <description>&lt;P&gt;Im not sure what you mean by the eval here. Do you mean if the value is in field1, make it the same for field2? Joins are ugly, we can also do similar like the below with stats.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=1 OR index=2 | stats list(a) AS A list(b) AS B
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Thats going to give you a list of the values, but it wont provide a gap between values.. Maybe why youre trying to do a join?&lt;/P&gt;

&lt;P&gt;If there is a time field associated with these, its much easier to do &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=1 OR index=2 | stats list(a) AS A list(b) AS B by _time | eval B=if(isnull(B),A,B) | table A B 
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 19 Jan 2016 14:19:08 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-I-edit-my-current-search-to-compare-the-values-of-2/m-p/236534#M70266</guid>
      <dc:creator>esix_splunk</dc:creator>
      <dc:date>2016-01-19T14:19:08Z</dc:date>
    </item>
    <item>
      <title>Re: How do I edit my current search to compare the values of 2 fields efficiently?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-I-edit-my-current-search-to-compare-the-values-of-2/m-p/236535#M70267</link>
      <description>&lt;P&gt;Try something like this. This is inline with your expected output&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=1 OR index=2 | eval common=coalesce(field1,field2) | stats values(index) as index by common | eval Field1=case(mvcount(index)=2,common, mvcount(index)=1 AND index="1",common,1=1,"") | eval Field2=case(mvcount(index)=2,common, mvcount(index)=1 AND index="2",common,1=1,"") | table Field1 Field2
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 19 Jan 2016 15:12:23 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-I-edit-my-current-search-to-compare-the-values-of-2/m-p/236535#M70267</guid>
      <dc:creator>somesoni2</dc:creator>
      <dc:date>2016-01-19T15:12:23Z</dc:date>
    </item>
    <item>
      <title>Re: How do I edit my current search to compare the values of 2 fields efficiently?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-I-edit-my-current-search-to-compare-the-values-of-2/m-p/236536#M70268</link>
      <description>&lt;P&gt;Thank you , I got on the right track by using stats list().&lt;/P&gt;

&lt;P&gt;I cam up with a different solution, but with stats. I didn´t compare the field, I just took &lt;CODE&gt;stats count&lt;/CODE&gt;to see how often the field is present.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt; stats count list(origin) as origins list(sourcetype) list(type) by field 
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 20 Jan 2016 09:44:48 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-I-edit-my-current-search-to-compare-the-values-of-2/m-p/236536#M70268</guid>
      <dc:creator>dkeck</dc:creator>
      <dc:date>2016-01-20T09:44:48Z</dc:date>
    </item>
  </channel>
</rss>

