<?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 to get common values in two different fields in two different searches in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-to-get-common-values-in-two-different-fields-in-two/m-p/451950#M127976</link>
    <description>&lt;P&gt;Like this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;(index=main AND source=os) OR (index=patch AND sourcetype=csv
| eval ComputerName=coalesce(ComputerName, extracted_Host)
| stats dc(index) AS index_count dc(BuildNumber) AS BuildNumber_count dc(patchlevel) AS patchlevel_count BY ComputerName
| where index_count &amp;gt; 1 AND BuildNumber_count != patchlevel_count
&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Fri, 05 Jul 2019 23:11:54 GMT</pubDate>
    <dc:creator>woodcock</dc:creator>
    <dc:date>2019-07-05T23:11:54Z</dc:date>
    <item>
      <title>How to get common values in two different fields in two different searches</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-get-common-values-in-two-different-fields-in-two/m-p/451944#M127970</link>
      <description>&lt;P&gt;Hi all, I'd be grateful if you could help me with this. I have read other similar questions but none of them seem to solve the problem.&lt;/P&gt;

&lt;P&gt;I have two searches:&lt;BR /&gt;
&lt;STRONG&gt;Search 1:&lt;/STRONG&gt; &lt;CODE&gt;index=main source=os&lt;/CODE&gt; &lt;BR /&gt;
&lt;STRONG&gt;Search 2:&lt;/STRONG&gt; &lt;CODE&gt;index=patch sourcetype=csv&lt;/CODE&gt;&lt;/P&gt;

&lt;P&gt;In search 1, there is a field that has workstation IDs, and the field is called 'ComputerName'&lt;BR /&gt;
In search 2, the same field exists but the name is 'extracted_Hosts'&lt;/P&gt;

&lt;P&gt;So what I want to do is look at both searches and get workstation IDs that exist in &lt;STRONG&gt;both&lt;/STRONG&gt;, and then use these events to pipe into another function.&lt;/P&gt;

&lt;P&gt;Example:&lt;BR /&gt;
Search 1: index=main source=os | stats values(ComputerName)&lt;BR /&gt;
Result: &lt;BR /&gt;
&lt;STRONG&gt;W123456&lt;/STRONG&gt;&lt;BR /&gt;
&lt;STRONG&gt;W789123&lt;/STRONG&gt;&lt;BR /&gt;
W456789&lt;BR /&gt;
W123321&lt;BR /&gt;
&lt;STRONG&gt;W789987&lt;/STRONG&gt;&lt;/P&gt;

&lt;P&gt;Actual number of results is 30,271&lt;/P&gt;

&lt;P&gt;Search 2: index=patch sourcetype=csv | stats values(extracted_Host)&lt;BR /&gt;
&lt;STRONG&gt;W123456&lt;/STRONG&gt;&lt;BR /&gt;
W154658&lt;BR /&gt;
&lt;STRONG&gt;W789123&lt;/STRONG&gt;&lt;BR /&gt;
W546589&lt;BR /&gt;
&lt;STRONG&gt;W789987&lt;/STRONG&gt;&lt;/P&gt;

&lt;P&gt;Actual number of results is 18,672&lt;/P&gt;

&lt;P&gt;So the output I want is:&lt;BR /&gt;
&lt;STRONG&gt;W123456&lt;/STRONG&gt;&lt;BR /&gt;
&lt;STRONG&gt;W789123&lt;/STRONG&gt;&lt;BR /&gt;
&lt;STRONG&gt;W789987&lt;/STRONG&gt;&lt;/P&gt;

&lt;P&gt;Your help is much appreciated!&lt;/P&gt;

&lt;HR /&gt;

&lt;P&gt;Here is what I want to do with the data, grateful if you can help with this but I think I need to figure out the above before that.&lt;/P&gt;

&lt;P&gt;The search 1 (source=os) has a field called 'BuildNumber' which refers to the Windows 10 build version. The search 2 (index=patch) has a field called 'patchlevel' which is the same as 'BuildNumber', but they are different numbers, so for example a version of Windows 10 could have BuildNumber = 1703 and patchlevel = 15063. &lt;STRONG&gt;I want to use the data from the previous search which gives me the workstations that are common in both sources, and then get a count of each Build Number and patch level, and see if there is any discrepancy.&lt;/STRONG&gt; &lt;/P&gt;

&lt;P&gt;Hope I've explained this well enough, let me know if I haven't! Thanks again. &lt;/P&gt;</description>
      <pubDate>Fri, 28 Jun 2019 08:50:11 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-get-common-values-in-two-different-fields-in-two/m-p/451944#M127970</guid>
      <dc:creator>xiantros</dc:creator>
      <dc:date>2019-06-28T08:50:11Z</dc:date>
    </item>
    <item>
      <title>Re: How to get common values in two different fields in two different searches</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-get-common-values-in-two-different-fields-in-two/m-p/451945#M127971</link>
      <description>&lt;P&gt;See if this gets you close to what you want.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;(index=main source=os) OR (index=patch sourcetype=csv) 
| eval computer = coalesce(ComputerName, extracted_Host)
| stats values(BuildNumber) as BuildNumbers, values(patchlevel) as patchlevels by computer
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 28 Jun 2019 12:35:11 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-get-common-values-in-two-different-fields-in-two/m-p/451945#M127971</guid>
      <dc:creator>richgalloway</dc:creator>
      <dc:date>2019-06-28T12:35:11Z</dc:date>
    </item>
    <item>
      <title>Re: How to get common values in two different fields in two different searches</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-get-common-values-in-two-different-fields-in-two/m-p/451946#M127972</link>
      <description>&lt;P&gt;Thanks for your answer. Correct me if I'm wrong but seems to put all values in 'ComputerName' and 'extracted_Host' fields into one field called 'computer'? I want to make sure that the values I get exist are in both fields, and I don't want any value that exists in only one field.. &lt;/P&gt;</description>
      <pubDate>Fri, 28 Jun 2019 13:27:38 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-get-common-values-in-two-different-fields-in-two/m-p/451946#M127972</guid>
      <dc:creator>xiantros</dc:creator>
      <dc:date>2019-06-28T13:27:38Z</dc:date>
    </item>
    <item>
      <title>Re: How to get common values in two different fields in two different searches</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-get-common-values-in-two-different-fields-in-two/m-p/451947#M127973</link>
      <description>&lt;P&gt;ComputerName and extracted_Host are not present in both indexes so we can't select events that have both.&lt;BR /&gt;
The &lt;CODE&gt;coalesce&lt;/CODE&gt; function, however, creates a new field that contains the value of either ComputerName or extracted_Host, whichever is not null.  That allows the &lt;CODE&gt;stats&lt;/CODE&gt; function to match up the two indexes and produce the desired results.&lt;/P&gt;</description>
      <pubDate>Wed, 30 Sep 2020 01:08:03 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-get-common-values-in-two-different-fields-in-two/m-p/451947#M127973</guid>
      <dc:creator>richgalloway</dc:creator>
      <dc:date>2020-09-30T01:08:03Z</dc:date>
    </item>
    <item>
      <title>Re: How to get common values in two different fields in two different searches</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-get-common-values-in-two-different-fields-in-two/m-p/451948#M127974</link>
      <description>&lt;P&gt;Ok so in this case let's say index 'main' has values in ComputerName as a, b, d, e and index 'patch' has values for extracted_Host as a, b, c, f. Is the field created by &lt;CODE&gt;coalesce&lt;/CODE&gt; function going to give me a, b, c, ,d e, f or a, b ?&lt;/P&gt;

&lt;P&gt;I want the result to be a, b as they are the common values that exist in both.&lt;/P&gt;</description>
      <pubDate>Sat, 29 Jun 2019 09:00:42 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-get-common-values-in-two-different-fields-in-two/m-p/451948#M127974</guid>
      <dc:creator>xiantros</dc:creator>
      <dc:date>2019-06-29T09:00:42Z</dc:date>
    </item>
    <item>
      <title>Re: How to get common values in two different fields in two different searches</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-get-common-values-in-two-different-fields-in-two/m-p/451949#M127975</link>
      <description>&lt;P&gt;The &lt;CODE&gt;coalesce&lt;/CODE&gt; function returns a single value that is the first of its arguments which is not null.&lt;BR /&gt;
Keep in mind the function operates on one event at a time so it will only see one value for ComputerName and one value for extracted_Host.&lt;/P&gt;</description>
      <pubDate>Tue, 02 Jul 2019 12:56:02 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-get-common-values-in-two-different-fields-in-two/m-p/451949#M127975</guid>
      <dc:creator>richgalloway</dc:creator>
      <dc:date>2019-07-02T12:56:02Z</dc:date>
    </item>
    <item>
      <title>Re: How to get common values in two different fields in two different searches</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-get-common-values-in-two-different-fields-in-two/m-p/451950#M127976</link>
      <description>&lt;P&gt;Like this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;(index=main AND source=os) OR (index=patch AND sourcetype=csv
| eval ComputerName=coalesce(ComputerName, extracted_Host)
| stats dc(index) AS index_count dc(BuildNumber) AS BuildNumber_count dc(patchlevel) AS patchlevel_count BY ComputerName
| where index_count &amp;gt; 1 AND BuildNumber_count != patchlevel_count
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 05 Jul 2019 23:11:54 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-get-common-values-in-two-different-fields-in-two/m-p/451950#M127976</guid>
      <dc:creator>woodcock</dc:creator>
      <dc:date>2019-07-05T23:11:54Z</dc:date>
    </item>
    <item>
      <title>Re: How to get common values in two different fields in two different searches</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-get-common-values-in-two-different-fields-in-two/m-p/451951#M127977</link>
      <description>&lt;P&gt;@xiantros, does it solve your problem?&lt;/P&gt;</description>
      <pubDate>Tue, 08 Oct 2019 07:56:24 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-get-common-values-in-two-different-fields-in-two/m-p/451951#M127977</guid>
      <dc:creator>ankitkanchan</dc:creator>
      <dc:date>2019-10-08T07:56:24Z</dc:date>
    </item>
  </channel>
</rss>

