<?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 do I extract the file path up to a variable number of '\'s? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-do-I-extract-the-file-path-up-to-a-variable-number-of-s/m-p/394512#M114572</link>
    <description>&lt;P&gt;Can you please use the 101010 button in the editor toolbar to post your search code as code, now certain special characters are disappearing. I'm guessing perhaps the escaping of the &lt;CODE&gt;\&lt;/CODE&gt; isn't working perfectly, but that's a bit hard to say with the search code being messed up by the splunk-answers board software.&lt;/P&gt;

&lt;P&gt;Otherwise try and take a screenshot and upload that somewhere to share.&lt;/P&gt;</description>
    <pubDate>Mon, 19 Nov 2018 13:10:15 GMT</pubDate>
    <dc:creator>FrankVl</dc:creator>
    <dc:date>2018-11-19T13:10:15Z</dc:date>
    <item>
      <title>How do I extract the file path up to a variable number of '\'s?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-I-extract-the-file-path-up-to-a-variable-number-of-s/m-p/394509#M114569</link>
      <description>&lt;P&gt;Good afternoon, &lt;/P&gt;

&lt;P&gt;Many thanks in advance for any advice....&lt;/P&gt;

&lt;P&gt;I am looking to extract the file path up to a variable number of back slashes&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;C:\a\b\c\d\e
C:\a\b\c\d\e\f\g
C:\a\b\c\....\n
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;I've looked at makemv, split, extract, regex but I can't see a way to get them to work for a variable number.&lt;/P&gt;

&lt;P&gt;Eventually, I would like a form so someone can quickly choose how far down a path to go.&lt;/P&gt;

&lt;P&gt;I would like to show how many entries match the path as well as the paths.&lt;/P&gt;

&lt;P&gt;Regards &lt;/P&gt;</description>
      <pubDate>Thu, 15 Nov 2018 16:39:49 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-I-extract-the-file-path-up-to-a-variable-number-of-s/m-p/394509#M114569</guid>
      <dc:creator>ChrisCLewis</dc:creator>
      <dc:date>2018-11-15T16:39:49Z</dc:date>
    </item>
    <item>
      <title>Re: How do I extract the file path up to a variable number of '\'s?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-I-extract-the-file-path-up-to-a-variable-number-of-s/m-p/394510#M114570</link>
      <description>&lt;P&gt;Like this?&lt;BR /&gt;
&lt;CODE&gt;(?&amp;lt;path&amp;gt;C:\\[^\\]+(?:\\[^\\]+){2})&lt;/CODE&gt;&lt;BR /&gt;
Vary the number between the &lt;CODE&gt;{}&lt;/CODE&gt; to vary the number of segments extracted (can also be 0).&lt;BR /&gt;
&lt;A href="https://regex101.com/r/wT5V6A/1"&gt;https://regex101.com/r/wT5V6A/1&lt;/A&gt;&lt;/P&gt;

&lt;P&gt;And you can tokenize that by replacing the number with $number_token$ or something like that.&lt;/P&gt;

&lt;P&gt;Update as per comments below. In Splunk search bar, this would look like this: &lt;CODE&gt;|rex field=full_path "(?&amp;lt;selected_path&amp;gt;.:\\\[^\\\]+(?:\\\[^\\\]+){2})"&lt;/CODE&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 16 Nov 2018 12:22:55 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-I-extract-the-file-path-up-to-a-variable-number-of-s/m-p/394510#M114570</guid>
      <dc:creator>FrankVl</dc:creator>
      <dc:date>2018-11-16T12:22:55Z</dc:date>
    </item>
    <item>
      <title>Re: How do I extract the file path up to a variable number of '\'s?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-I-extract-the-file-path-up-to-a-variable-number-of-s/m-p/394511#M114571</link>
      <description>&lt;P&gt;Many thanks for your help, it is working in regex101 but not on the data&lt;/P&gt;

&lt;P&gt;|rex field=_raw (?.:\[^\]+(?:\[^\]+){$number_token$})&lt;/P&gt;

&lt;P&gt;I did change "(?C:\" to "(?.:\" as path letter can change.&lt;BR /&gt;&lt;BR /&gt;
I've also used the field name in place of  _raw and a number instead of the token&lt;/P&gt;

&lt;P&gt;It is finding results but not pulling anything out into 'path'&lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2020 22:04:46 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-I-extract-the-file-path-up-to-a-variable-number-of-s/m-p/394511#M114571</guid>
      <dc:creator>ChrisCLewis</dc:creator>
      <dc:date>2020-09-29T22:04:46Z</dc:date>
    </item>
    <item>
      <title>Re: How do I extract the file path up to a variable number of '\'s?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-I-extract-the-file-path-up-to-a-variable-number-of-s/m-p/394512#M114572</link>
      <description>&lt;P&gt;Can you please use the 101010 button in the editor toolbar to post your search code as code, now certain special characters are disappearing. I'm guessing perhaps the escaping of the &lt;CODE&gt;\&lt;/CODE&gt; isn't working perfectly, but that's a bit hard to say with the search code being messed up by the splunk-answers board software.&lt;/P&gt;

&lt;P&gt;Otherwise try and take a screenshot and upload that somewhere to share.&lt;/P&gt;</description>
      <pubDate>Mon, 19 Nov 2018 13:10:15 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-I-extract-the-file-path-up-to-a-variable-number-of-s/m-p/394512#M114572</guid>
      <dc:creator>FrankVl</dc:creator>
      <dc:date>2018-11-19T13:10:15Z</dc:date>
    </item>
    <item>
      <title>Re: How do I extract the file path up to a variable number of '\'s?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-I-extract-the-file-path-up-to-a-variable-number-of-s/m-p/394513#M114573</link>
      <description>&lt;P&gt;Played around with it myself a bit, looks like it needs tripple backslash to result in actual backslash match in rex command.&lt;/P&gt;

&lt;P&gt;Try this run-anywhere query incl. sample data:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| makeresults | eval full_path="C:\a\b\c\d\e" |rex field=full_path "(?&amp;lt;selected_path&amp;gt;.:\\\[^\\\]+(?:\\\[^\\\]+){2})"
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 19 Nov 2018 13:14:39 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-I-extract-the-file-path-up-to-a-variable-number-of-s/m-p/394513#M114573</guid>
      <dc:creator>FrankVl</dc:creator>
      <dc:date>2018-11-19T13:14:39Z</dc:date>
    </item>
    <item>
      <title>Re: How do I extract the file path up to a variable number of '\'s?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-I-extract-the-file-path-up-to-a-variable-number-of-s/m-p/394514#M114574</link>
      <description>&lt;P&gt;Many thanks for the speedy (and working) update.&lt;/P&gt;

&lt;P&gt;It's working perfectly - now to really get to grips with regex.... &lt;/P&gt;</description>
      <pubDate>Mon, 19 Nov 2018 13:28:19 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-I-extract-the-file-path-up-to-a-variable-number-of-s/m-p/394514#M114574</guid>
      <dc:creator>ChrisCLewis</dc:creator>
      <dc:date>2018-11-19T13:28:19Z</dc:date>
    </item>
  </channel>
</rss>

