<?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 compare fields from csv and search, then add the result as a new column in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-to-compare-fields-from-csv-and-search-then-add-the-result-as/m-p/463751#M130746</link>
    <description>&lt;P&gt;Come back and try it now.&lt;/P&gt;</description>
    <pubDate>Fri, 25 Oct 2019 22:49:49 GMT</pubDate>
    <dc:creator>woodcock</dc:creator>
    <dc:date>2019-10-25T22:49:49Z</dc:date>
    <item>
      <title>How to compare fields from csv and search, then add the result as a new column</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-compare-fields-from-csv-and-search-then-add-the-result-as/m-p/463742#M130737</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;

&lt;P&gt;I'm having a little trouble solving this one.&lt;BR /&gt;
I managed to extract all hosts in Splunk in a table with events counted by path with the following search  :&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;search index=* 
| rex field=source "(?&amp;lt;file_path&amp;gt;.*\\\)" 
| rex field=source "(?&amp;lt;file_path&amp;gt;.*\/)" 
| chart count over file_path by host limit=0 
| fields - source    
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;In the other hand, I have a full inventory of our network in a csv file.&lt;BR /&gt;
I would like to be able to filter Splunk hosts by Location (this Location field is present in the full inventory csv). &lt;BR /&gt;
I believe that I have to use the Lookup command but I can't find out how to use it. (Both the csv and the search table have a hostname field)&lt;/P&gt;

&lt;P&gt;The Splunk query above gives a table &lt;STRONG&gt;like this :&lt;/STRONG&gt;&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;------------+-------+-------+-------+-----+
            | Path1 | Path2 | Path3 | ... |
------------+-------+-------+-------+-----+
Host_1      |  100  |    0  |   200 | ... |
Host_2      |  250  |  1200 |    2  | ... |
Host_3      |   0   |   10  |    0  | ... |
------------+-------+-------+-------+-----+
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;And I would like to add a Location column with information from the CSV to look &lt;STRONG&gt;like this :&lt;/STRONG&gt;&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;------------+--------+-------+-------+-------+-----+
            |Location| Path1 | Path2 | Path3 | ... |
------------+--------+-------+-------+-------+-----+
Host_1      |   USA  |  100  |    0  |   200 | ... |
Host_2      |   U.K  |  250  |  1200 |    2  | ... |
Host_3      |   USA  |   0   |   10  |    0  | ... |
------------+--------+-------+-------+-------+-----+
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Thank you for your help !&lt;/P&gt;</description>
      <pubDate>Mon, 21 Oct 2019 05:11:27 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-compare-fields-from-csv-and-search-then-add-the-result-as/m-p/463742#M130737</guid>
      <dc:creator>romainbouajila</dc:creator>
      <dc:date>2019-10-21T05:11:27Z</dc:date>
    </item>
    <item>
      <title>Re: How to compare fields from csv and search, then add the result as a new column</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-compare-fields-from-csv-and-search-then-add-the-result-as/m-p/463743#M130738</link>
      <description>&lt;P&gt;Hi  romainbouajila,&lt;BR /&gt;
in a chart, you usually cannot use more than two fields, but you could use a workaround, if acceptable:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=* 
| rex field=source "(?&amp;lt;file_path&amp;gt;.*\\\)" 
| rex field=source "(?&amp;lt;file_path&amp;gt;.*\/)" 
| lookup location_lookup.csv hostname OUTPUT Location
| eval host=hostname." (".Location.")"
| chart count over file_path by host limit=0 
| fields - source 
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;(it's not clear for me if you have always field hostname or host, anyway the search logic is correct)&lt;BR /&gt;
In this way you have in the first column hostname and Location.&lt;/P&gt;

&lt;P&gt;Ciao.&lt;BR /&gt;
Giuseppe&lt;/P&gt;</description>
      <pubDate>Tue, 22 Oct 2019 07:00:29 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-compare-fields-from-csv-and-search-then-add-the-result-as/m-p/463743#M130738</guid>
      <dc:creator>gcusello</dc:creator>
      <dc:date>2019-10-22T07:00:29Z</dc:date>
    </item>
    <item>
      <title>Re: How to compare fields from csv and search, then add the result as a new column</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-compare-fields-from-csv-and-search-then-add-the-result-as/m-p/463744#M130739</link>
      <description>&lt;P&gt;Like this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=* 
| rex field=source "(?&amp;lt;file_path&amp;gt;((?:.*\\\)|(?:.*\/)))"
| chart count over file_path by host limit=0 
| lookup YouLookupFile.csv Hostname AS host
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 22 Oct 2019 08:24:09 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-compare-fields-from-csv-and-search-then-add-the-result-as/m-p/463744#M130739</guid>
      <dc:creator>woodcock</dc:creator>
      <dc:date>2019-10-22T08:24:09Z</dc:date>
    </item>
    <item>
      <title>Re: How to compare fields from csv and search, then add the result as a new column</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-compare-fields-from-csv-and-search-then-add-the-result-as/m-p/463745#M130740</link>
      <description>&lt;P&gt;Hello woodcock, I don't get how that query would add a new "Location" column to my table&lt;BR /&gt;
Thanks for your help&lt;/P&gt;</description>
      <pubDate>Tue, 22 Oct 2019 09:28:25 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-compare-fields-from-csv-and-search-then-add-the-result-as/m-p/463745#M130740</guid>
      <dc:creator>romainbouajila</dc:creator>
      <dc:date>2019-10-22T09:28:25Z</dc:date>
    </item>
    <item>
      <title>Re: How to compare fields from csv and search, then add the result as a new column</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-compare-fields-from-csv-and-search-then-add-the-result-as/m-p/463746#M130741</link>
      <description>&lt;P&gt;Ciao Giuseppe !&lt;BR /&gt;
Thank you very much for your help. To answer your question, "Hostname" is in my CSV and "host" in data source.&lt;BR /&gt;
I tried to run your query and that works just fine, thank you.&lt;BR /&gt;
Is it possible though to add a column with the location ? That would make it way more easy to use in Excel or in a dashboard&lt;/P&gt;</description>
      <pubDate>Tue, 22 Oct 2019 09:37:45 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-compare-fields-from-csv-and-search-then-add-the-result-as/m-p/463746#M130741</guid>
      <dc:creator>romainbouajila</dc:creator>
      <dc:date>2019-10-22T09:37:45Z</dc:date>
    </item>
    <item>
      <title>Re: How to compare fields from csv and search, then add the result as a new column</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-compare-fields-from-csv-and-search-then-add-the-result-as/m-p/463747#M130742</link>
      <description>&lt;P&gt;Hi romainbouajila,&lt;BR /&gt;
if you have "Hostname" in CSV and "host" in search you have only to modify the lookup command&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt; index=* 
 | rex field=source "(?&amp;lt;file_path&amp;gt;.*\\\)" 
 | rex field=source "(?&amp;lt;file_path&amp;gt;.*\/)" 
 | lookup location_lookup.csv Hostname As host OUTPUT Location
 | eval host=host." (".Location.")"
 | chart count over file_path by host limit=0 
 | fields - source 
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;To divide again the host from the Location, you should try something like this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt; index=* 
 | rex field=source "(?&amp;lt;file_path&amp;gt;.*\\\)" 
 | rex field=source "(?&amp;lt;file_path&amp;gt;.*\/)" 
 | lookup location_lookup.csv Hostname As host OUTPUT Location
 | eval host=host." (".Location.")"
 | chart count over file_path by host limit=0 
 | rex field=host "^(?&amp;lt;hostname&amp;gt;[^\(]*)\((?&amp;lt;Location&amp;gt;.*)"
 | table hostname Location path*
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Ciao.&lt;BR /&gt;
Giuseppe&lt;/P&gt;</description>
      <pubDate>Tue, 22 Oct 2019 10:30:08 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-compare-fields-from-csv-and-search-then-add-the-result-as/m-p/463747#M130742</guid>
      <dc:creator>gcusello</dc:creator>
      <dc:date>2019-10-22T10:30:08Z</dc:date>
    </item>
    <item>
      <title>Re: How to compare fields from csv and search, then add the result as a new column</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-compare-fields-from-csv-and-search-then-add-the-result-as/m-p/463748#M130743</link>
      <description>&lt;P&gt;I updated my answer; try it now.&lt;/P&gt;</description>
      <pubDate>Tue, 22 Oct 2019 13:40:39 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-compare-fields-from-csv-and-search-then-add-the-result-as/m-p/463748#M130743</guid>
      <dc:creator>woodcock</dc:creator>
      <dc:date>2019-10-22T13:40:39Z</dc:date>
    </item>
    <item>
      <title>Re: How to compare fields from csv and search, then add the result as a new column</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-compare-fields-from-csv-and-search-then-add-the-result-as/m-p/463749#M130744</link>
      <description>&lt;P&gt;Hi Giuseppe,&lt;/P&gt;

&lt;P&gt;I tried running the first query and then the one you submitted and I don't have the same results.&lt;BR /&gt;
My query returns 148 different file_path and the other one returns only 31. Do you know where that could come from ?&lt;BR /&gt;
Also I think I will rework the csv "by hand" and not include the 3rd &lt;CODE&gt;rex&lt;/CODE&gt; that splits hostname and location, in order to save some resources &lt;/P&gt;</description>
      <pubDate>Thu, 24 Oct 2019 08:55:09 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-compare-fields-from-csv-and-search-then-add-the-result-as/m-p/463749#M130744</guid>
      <dc:creator>romainbouajila</dc:creator>
      <dc:date>2019-10-24T08:55:09Z</dc:date>
    </item>
    <item>
      <title>Re: How to compare fields from csv and search, then add the result as a new column</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-compare-fields-from-csv-and-search-then-add-the-result-as/m-p/463750#M130745</link>
      <description>&lt;P&gt;Hi romainbouajila,&lt;BR /&gt;
if you can simplify your search it is surely an advantage even if I don't think that an extra rex weighs much on it.&lt;BR /&gt;
In any case, to debug the results: remove the lines from the two searches one by one so as to see if and when you have the same number of results and if all the fields you use later are explained.&lt;/P&gt;

&lt;P&gt;Ciao.&lt;BR /&gt;
Giuseppe&lt;/P&gt;</description>
      <pubDate>Thu, 24 Oct 2019 09:03:54 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-compare-fields-from-csv-and-search-then-add-the-result-as/m-p/463750#M130745</guid>
      <dc:creator>gcusello</dc:creator>
      <dc:date>2019-10-24T09:03:54Z</dc:date>
    </item>
    <item>
      <title>Re: How to compare fields from csv and search, then add the result as a new column</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-compare-fields-from-csv-and-search-then-add-the-result-as/m-p/463751#M130746</link>
      <description>&lt;P&gt;Come back and try it now.&lt;/P&gt;</description>
      <pubDate>Fri, 25 Oct 2019 22:49:49 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-compare-fields-from-csv-and-search-then-add-the-result-as/m-p/463751#M130746</guid>
      <dc:creator>woodcock</dc:creator>
      <dc:date>2019-10-25T22:49:49Z</dc:date>
    </item>
  </channel>
</rss>

