<?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: Regex to find a directory in a path in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Regex-to-find-a-directory-in-a-path/m-p/410698#M190960</link>
    <description>&lt;P&gt;For myfacility field:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;...
| rex field=source "\/usr\/local\/myfiles\d+\/myfacility(?&amp;lt;myfacility&amp;gt;.*?)\/Debug\/ADT\/"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;And for everything between the /usr/local/myfiles? and the /Debug/ADT/ADT:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;...
| rex field=source "\/usr\/local\/myfiles(?&amp;lt;myfacilityPath&amp;gt;.*?)\/Debug\/ADT\/"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Hope it helps&lt;/P&gt;</description>
    <pubDate>Tue, 30 Jul 2019 17:49:22 GMT</pubDate>
    <dc:creator>jaime_ramirez</dc:creator>
    <dc:date>2019-07-30T17:49:22Z</dc:date>
    <item>
      <title>Regex to find a directory in a path</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Regex-to-find-a-directory-in-a-path/m-p/410697#M190959</link>
      <description>&lt;P&gt;I have these paths as sources  for an index (the paths are linux file system paths)&lt;/P&gt;

&lt;P&gt;/usr/local/myfiles1/myfacilityA/Debug/ADT/ADT_2019-07-30.txt&lt;BR /&gt;
/usr/local/myfiles2/myfacilityB/Debug/ADT/ADT_2019-07-30.txt&lt;BR /&gt;
/usr/local/myfiles1/myfacilityC/Debug/ADT/ADT_2019-07-30.txt&lt;/P&gt;

&lt;P&gt;i would like to be able to extract "myfacility" as a field so I can search for all of the events with that source path.&lt;/P&gt;

&lt;P&gt;It would be fantastic  to just capture everything between the /usr/local/myfiles? and the /Debug/ADT/ADT....&lt;/P&gt;</description>
      <pubDate>Wed, 30 Sep 2020 01:28:39 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Regex-to-find-a-directory-in-a-path/m-p/410697#M190959</guid>
      <dc:creator>rileyken</dc:creator>
      <dc:date>2020-09-30T01:28:39Z</dc:date>
    </item>
    <item>
      <title>Re: Regex to find a directory in a path</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Regex-to-find-a-directory-in-a-path/m-p/410698#M190960</link>
      <description>&lt;P&gt;For myfacility field:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;...
| rex field=source "\/usr\/local\/myfiles\d+\/myfacility(?&amp;lt;myfacility&amp;gt;.*?)\/Debug\/ADT\/"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;And for everything between the /usr/local/myfiles? and the /Debug/ADT/ADT:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;...
| rex field=source "\/usr\/local\/myfiles(?&amp;lt;myfacilityPath&amp;gt;.*?)\/Debug\/ADT\/"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Hope it helps&lt;/P&gt;</description>
      <pubDate>Tue, 30 Jul 2019 17:49:22 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Regex-to-find-a-directory-in-a-path/m-p/410698#M190960</guid>
      <dc:creator>jaime_ramirez</dc:creator>
      <dc:date>2019-07-30T17:49:22Z</dc:date>
    </item>
    <item>
      <title>Re: Regex to find a directory in a path</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Regex-to-find-a-directory-in-a-path/m-p/410699#M190961</link>
      <description>&lt;P&gt;This was just what I was looking for! Thanks Jamie&lt;/P&gt;</description>
      <pubDate>Wed, 31 Jul 2019 12:11:56 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Regex-to-find-a-directory-in-a-path/m-p/410699#M190961</guid>
      <dc:creator>rileyken</dc:creator>
      <dc:date>2019-07-31T12:11:56Z</dc:date>
    </item>
    <item>
      <title>Re: Regex to find a directory in a path</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Regex-to-find-a-directory-in-a-path/m-p/531817#M190962</link>
      <description>&lt;P&gt;If you would like to avoid cumbersome regex rules and are just looking for the fourth directory (or 0-4 directory path) you may want to consider the &lt;A title="Splunk Reference - Multivalue eval functions" href="https://docs.splunk.com/Documentation/Splunk/latest/SearchReference/MultivalueEvalFunctions" target="_blank" rel="noopener"&gt;Splunk Multivalue eval functions&lt;/A&gt; "mvindex", "split", and "mvjoin" to do the work for you... note that the "nomv" commands are optional in most cases.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="css"&gt;| makeresults
| eval filepathname="/usr/local/myfiles1/myfacilityA/Debug/ADT/ADT_2019-07-30.txt"
| eval Dir4=mvindex(split(filepathname,"/"),4,4) 
| nomv Dir4
| eval Dir0to4=mvjoin(mvindex( split(filepathname,"/"),0,4), "/") 
| nomv Dir0to4&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 03 Dec 2020 06:32:58 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Regex-to-find-a-directory-in-a-path/m-p/531817#M190962</guid>
      <dc:creator>bwlm</dc:creator>
      <dc:date>2020-12-03T06:32:58Z</dc:date>
    </item>
  </channel>
</rss>

