<?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: split based on lookup in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/split-based-on-lookup/m-p/334822#M99528</link>
    <description>&lt;P&gt;you can create a field for the critical directory&lt;BR /&gt;
here is an example:&lt;BR /&gt;
&lt;A href="https://answers.splunk.com/answers/468028/regex-source-and-destination-files-with-path-filen.html"&gt;https://answers.splunk.com/answers/468028/regex-source-and-destination-files-with-path-filen.html&lt;/A&gt;&lt;/P&gt;</description>
    <pubDate>Thu, 27 Jul 2017 17:42:42 GMT</pubDate>
    <dc:creator>adonio</dc:creator>
    <dc:date>2017-07-27T17:42:42Z</dc:date>
    <item>
      <title>split based on lookup</title>
      <link>https://community.splunk.com/t5/Splunk-Search/split-based-on-lookup/m-p/334821#M99527</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;

&lt;P&gt;I have a set of windows events (4656 and 4663)  which contain fullpathnames. I also have a list of 'critical' directories as a lookup. I would like to split the fullpathname field into 2 new fields: One containing the 'critical' directory and one containing the remainder. &lt;/P&gt;

&lt;P&gt;Example:&lt;BR /&gt;
Full path: T:\k-share\A&amp;amp;O IR\Bestuursrelaties\W_BR_Archief\OPF\gedragscode\2007\brief aan A. Atmopawiro inzake gedragscode 2007.doc&lt;BR /&gt;
Critical directory: T:\k-share\A&amp;amp;O IR\Bestuursrelaties\W_BR_Archief&lt;BR /&gt;
Remainder: OPF\gedragscode\2007\brief aan A. Atmopawiro inzake gedragscode 2007.doc&lt;/P&gt;

&lt;P&gt;What is the best option to achieve this?&lt;/P&gt;

&lt;P&gt;best regards,&lt;BR /&gt;
Coen van Dijk&lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2020 15:05:22 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/split-based-on-lookup/m-p/334821#M99527</guid>
      <dc:creator>coenvandijk</dc:creator>
      <dc:date>2020-09-29T15:05:22Z</dc:date>
    </item>
    <item>
      <title>Re: split based on lookup</title>
      <link>https://community.splunk.com/t5/Splunk-Search/split-based-on-lookup/m-p/334822#M99528</link>
      <description>&lt;P&gt;you can create a field for the critical directory&lt;BR /&gt;
here is an example:&lt;BR /&gt;
&lt;A href="https://answers.splunk.com/answers/468028/regex-source-and-destination-files-with-path-filen.html"&gt;https://answers.splunk.com/answers/468028/regex-source-and-destination-files-with-path-filen.html&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 27 Jul 2017 17:42:42 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/split-based-on-lookup/m-p/334822#M99528</guid>
      <dc:creator>adonio</dc:creator>
      <dc:date>2017-07-27T17:42:42Z</dc:date>
    </item>
    <item>
      <title>Re: split based on lookup</title>
      <link>https://community.splunk.com/t5/Splunk-Search/split-based-on-lookup/m-p/334823#M99529</link>
      <description>&lt;P&gt;Here's a run-anywhere sample that creates a rex.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| makeresults 
| eval critical="T:\k-share\A&amp;amp;O IR\Bestuursrelaties\W_BR_Archief!!!!C:\George\Washington\!!!!T:\k-share\Mickey.Mouse+Minnie*Mouse" 
| makemv delim="!!!!"  critical 
| table critical 
| mvexpand critical 
| rename COMMENT as "everything above this just generates test data with each critical directory in a single field called critical"

| rename COMMENT as "now we begin to format the records into a regular expression that will find directory1 or directory 2 etc"
| format "(?i)^(?&amp;lt;critical&amp;gt;" "" "3" "" "|" ")"
| rename search as searchRex
| rename COMMENT as "slashes have already been escaped, but we have to escape * and . and +"
| rex mode=sed field=searchRex "s/([\.\*\+])/!!!\1/g"
| rex mode=sed field=searchRex "s/!!!/\\\/g"
| rename COMMENT as "kill the field name and associated quotes"
| rex mode=sed field=searchRex "s/ critical=//g"
| rex mode=sed field=searchRex "s/\"  \| \"/|/g"
| rex mode=sed field=searchRex "s/&amp;gt; \"/&amp;gt;/g"
| rex mode=sed field=searchRex "s/\"  \)/)(?&amp;lt;remainder&amp;gt;.*)$/g"
| eval searchRex = "\"".searchRex."\""
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;The sample rex looks like this - &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;"(?i)^(?&amp;lt;critical&amp;gt;T:\\k-share\\A&amp;amp;O IR\\Bestuursrelaties\\W_BR_Archief|C:\\George\\Washington\\|T:\\k-share\\Mickey\.Mouse\+Minnie\*Mouse)(?&amp;lt;remainder&amp;gt;.*)$" 
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Now, just in case that looks overcomplicated, let me get you a simple example of how it ends up - &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| rex field=fulldirectory  "(?i)^(?&amp;lt;critical&amp;gt;T:\\critical\\directory1|T:\\critical\\directory2|T:\\critical\\directory3)(?&amp;lt;remainder&amp;gt;.*)$" 
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;That &lt;CODE&gt;rex&lt;/CODE&gt; will put the value of any matching directory into the field named "critical" and then put anything left over into the field "remainder". &lt;/P&gt;

&lt;P&gt;Unfortunately, the &lt;CODE&gt;rex&lt;/CODE&gt; command does not natively take a variable for the regular expression string, so we're going to have to use the &lt;CODE&gt;map&lt;/CODE&gt; command to have that happen. &lt;/P&gt;

&lt;P&gt;And, &lt;CODE&gt;map&lt;/CODE&gt; is a bit finnicky, so for testing you will need to use &lt;CODE&gt;head&lt;/CODE&gt; to limit the results, and probably run a few times before you get it all to work right together.   &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt; | map search="search  ...your other search terms here... | use head 5  here for testing | rex field=fulldirectory $searchRex$ | ...remainder of your search..."
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 27 Jul 2017 23:41:07 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/split-based-on-lookup/m-p/334823#M99529</guid>
      <dc:creator>DalJeanis</dc:creator>
      <dc:date>2017-07-27T23:41:07Z</dc:date>
    </item>
  </channel>
</rss>

