<?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 rex syntax to parse source path for a sub-directory name and the file name in Getting Data In</title>
    <link>https://community.splunk.com/t5/Getting-Data-In/rex-syntax-to-parse-source-path-for-a-sub-directory-name-and-the/m-p/100121#M20932</link>
    <description>&lt;P&gt;I am trying to parse source path for a sub-directory name and its file name.  My source files are as follows:&lt;/P&gt;

&lt;P&gt;source=/home/sd1/sd2/sd3/(subdir1)/file1.out&lt;BR /&gt;
source=/home/sd1/sd2/sd3/(subdir1)/sd4/file2.log&lt;BR /&gt;
source=/home/sd1/sd2/sd3/(subdir1)/sd4/sd5/file3.out&lt;BR /&gt;
source=/home/sd1/sd2/sd3/(subdir1)/sd4/sd5/sd6/file4.out&lt;/P&gt;

&lt;P&gt;I can't seem to get the syntax correct with the following:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;Exception sourcetype=EDGDC2 | rex ".*?(?&amp;lt;exception&amp;gt;(?:\w+\.)+\w*?Exception).*" | rex field=source "(/\w*)+(/\w*)+(/\w*)+(/\w*)+(?&amp;lt;subdir1&amp;gt;(/\w*))+/+(?&amp;lt;fname&amp;gt;(\w*+\.+\w*))+" | stats count by exception, subdir1
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;The above rex will always get the last sub-directory where the file is.  Tried several different variation but the above is the closest I get...&lt;/P&gt;</description>
    <pubDate>Thu, 18 Apr 2013 18:22:20 GMT</pubDate>
    <dc:creator>vincenty</dc:creator>
    <dc:date>2013-04-18T18:22:20Z</dc:date>
    <item>
      <title>rex syntax to parse source path for a sub-directory name and the file name</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/rex-syntax-to-parse-source-path-for-a-sub-directory-name-and-the/m-p/100121#M20932</link>
      <description>&lt;P&gt;I am trying to parse source path for a sub-directory name and its file name.  My source files are as follows:&lt;/P&gt;

&lt;P&gt;source=/home/sd1/sd2/sd3/(subdir1)/file1.out&lt;BR /&gt;
source=/home/sd1/sd2/sd3/(subdir1)/sd4/file2.log&lt;BR /&gt;
source=/home/sd1/sd2/sd3/(subdir1)/sd4/sd5/file3.out&lt;BR /&gt;
source=/home/sd1/sd2/sd3/(subdir1)/sd4/sd5/sd6/file4.out&lt;/P&gt;

&lt;P&gt;I can't seem to get the syntax correct with the following:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;Exception sourcetype=EDGDC2 | rex ".*?(?&amp;lt;exception&amp;gt;(?:\w+\.)+\w*?Exception).*" | rex field=source "(/\w*)+(/\w*)+(/\w*)+(/\w*)+(?&amp;lt;subdir1&amp;gt;(/\w*))+/+(?&amp;lt;fname&amp;gt;(\w*+\.+\w*))+" | stats count by exception, subdir1
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;The above rex will always get the last sub-directory where the file is.  Tried several different variation but the above is the closest I get...&lt;/P&gt;</description>
      <pubDate>Thu, 18 Apr 2013 18:22:20 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/rex-syntax-to-parse-source-path-for-a-sub-directory-name-and-the/m-p/100121#M20932</guid>
      <dc:creator>vincenty</dc:creator>
      <dc:date>2013-04-18T18:22:20Z</dc:date>
    </item>
    <item>
      <title>Re: rex syntax to parse source path for a sub-directory name and the file name</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/rex-syntax-to-parse-source-path-for-a-sub-directory-name-and-the/m-p/100122#M20933</link>
      <description>&lt;PRE&gt;&lt;CODE&gt;rex field=source "(/[^/]+){4}/(?&amp;lt;subdir1&amp;gt;[^/]+)/.*/(?&amp;lt;fname&amp;gt;.*)$"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;should work. &lt;/P&gt;

&lt;P&gt;EDIT: missed that you wanted the filename as well...&lt;/P&gt;

&lt;P&gt;/k&lt;/P&gt;</description>
      <pubDate>Thu, 18 Apr 2013 18:33:10 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/rex-syntax-to-parse-source-path-for-a-sub-directory-name-and-the/m-p/100122#M20933</guid>
      <dc:creator>kristian_kolb</dc:creator>
      <dc:date>2013-04-18T18:33:10Z</dc:date>
    </item>
  </channel>
</rss>

