<?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 extract these characters from fields in events to do an exact match against fields in my CSV lookup table? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-to-extract-these-characters-from-fields-in-events-to-do-an/m-p/201675#M58432</link>
    <description>&lt;P&gt;and then optionally add the next part on the end:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;... | fields - subCode
&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Mon, 19 Dec 2016 01:07:12 GMT</pubDate>
    <dc:creator>alexandermunce</dc:creator>
    <dc:date>2016-12-19T01:07:12Z</dc:date>
    <item>
      <title>How to extract these characters from fields in events to do an exact match against fields in my CSV lookup table?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-extract-these-characters-from-fields-in-events-to-do-an/m-p/201673#M58430</link>
      <description>&lt;P&gt;I have set up a lookup table csv file and this has been uploaded to Splunk, and I have also set up an associated stanza within transforms.conf which looks something like the below;&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;Table: sub_ref.csv
Fields: sub_code    company
        ABCD        Company 1
        ABCC        Company 2
        ABCA        Company 3
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;And in transforms.conf:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;[sub_ref]
sub_ref.csv
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Now this would be a fairly simple lookup, however the issue falls in the data.&lt;/P&gt;

&lt;P&gt;I am comparing three separate event fields against the &lt;STRONG&gt;sub_ref&lt;/STRONG&gt; lookup fields.&lt;/P&gt;

&lt;P&gt;For the sake of this example, lets say the event fields are: &lt;BR /&gt;
 - &lt;STRONG&gt;comp&lt;/STRONG&gt;&lt;BR /&gt;
- &lt;STRONG&gt;comp_id&lt;/STRONG&gt;&lt;BR /&gt;
- &lt;STRONG&gt;branch&lt;/STRONG&gt;&lt;/P&gt;

&lt;P&gt;The third event field (&lt;STRONG&gt;branch&lt;/STRONG&gt;) contains values which match exactly the data within the &lt;STRONG&gt;sub_code&lt;/STRONG&gt; field in my CSV lookup - ie, 4 characters.&lt;/P&gt;

&lt;P&gt;The first two event fields above, however, contain the lookup_field values followed by a trailing number, eg;&lt;/P&gt;

&lt;P&gt;&lt;STRONG&gt;comp&lt;/STRONG&gt; (event field)&lt;BR /&gt;
ABCD001&lt;BR /&gt;
ABCD002&lt;BR /&gt;
ABCC001&lt;BR /&gt;
ABCC002&lt;/P&gt;

&lt;P&gt;So, obviously as my testing has proven, I am not able to lookup against this event field using my current lookup field data as there is not an exact match.&lt;/P&gt;

&lt;P&gt;I have seen there is a way to include wildcards in my CSV lookup, by adding the following to my transforms.conf stanza:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;match_type = WILDCARD(sub_code)
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;However, this requires admin changes which I am trying to avoid at this stage.&lt;/P&gt;

&lt;P&gt;What I would rather do is to split up the first two fields into 2 new fields which extract the first 4 characters and then complete the lookup against these new fields - how would I go about this?&lt;/P&gt;

&lt;P&gt;Is this the best way to go about this?&lt;/P&gt;</description>
      <pubDate>Sun, 18 Dec 2016 23:47:17 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-extract-these-characters-from-fields-in-events-to-do-an/m-p/201673#M58430</guid>
      <dc:creator>alexandermunce</dc:creator>
      <dc:date>2016-12-18T23:47:17Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract these characters from fields in events to do an exact match against fields in my CSV lookup table?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-extract-these-characters-from-fields-in-events-to-do-an/m-p/201674#M58431</link>
      <description>&lt;P&gt;The solution I have come up with is as follows:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;rex field=comp "(?P&amp;lt;subCode&amp;gt;\w{4}).*" | lookup sub_ref sub_code AS subCode OUTPUT company AS Company
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 19 Dec 2016 01:06:40 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-extract-these-characters-from-fields-in-events-to-do-an/m-p/201674#M58431</guid>
      <dc:creator>alexandermunce</dc:creator>
      <dc:date>2016-12-19T01:06:40Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract these characters from fields in events to do an exact match against fields in my CSV lookup table?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-extract-these-characters-from-fields-in-events-to-do-an/m-p/201675#M58432</link>
      <description>&lt;P&gt;and then optionally add the next part on the end:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;... | fields - subCode
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 19 Dec 2016 01:07:12 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-extract-these-characters-from-fields-in-events-to-do-an/m-p/201675#M58432</guid>
      <dc:creator>alexandermunce</dc:creator>
      <dc:date>2016-12-19T01:07:12Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract these characters from fields in events to do an exact match against fields in my CSV lookup table?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-extract-these-characters-from-fields-in-events-to-do-an/m-p/201676#M58433</link>
      <description>&lt;P&gt;My next concern is that I am having troubles with the LOOKUP command - it will not let me check multiple event_fields against the SINGLE lookup_field;&lt;/P&gt;

&lt;P&gt;When I try to do a second lookup as below, there is no new field output;&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;... | lookup sub_ref sub_code AS comp, sub_code AS comp_ID OUTPUT company as Company
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Do I need to run the lookup command once for each event field and then output all as the one output field (Company)&lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2020 12:10:41 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-extract-these-characters-from-fields-in-events-to-do-an/m-p/201676#M58433</guid>
      <dc:creator>alexandermunce</dc:creator>
      <dc:date>2020-09-29T12:10:41Z</dc:date>
    </item>
  </channel>
</rss>

