<?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: Extract file name from path's for both windows and nix format in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-to-extract-file-name-from-path-s-for-both-windows-and-nix/m-p/640268#M221864</link>
    <description>&lt;P&gt;| rex field=file_path "([^\r\n\s\\\/]+[\\\/])+(?&amp;lt;file_name&amp;gt;.*)$"&lt;/P&gt;</description>
    <pubDate>Mon, 17 Apr 2023 17:58:22 GMT</pubDate>
    <dc:creator>woodcock</dc:creator>
    <dc:date>2023-04-17T17:58:22Z</dc:date>
    <item>
      <title>How to extract file name from path's for both windows and nix format?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-extract-file-name-from-path-s-for-both-windows-and-nix/m-p/640246#M221856</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;We have a data source containing File Path's from both Windows and Linux formats.&amp;nbsp; Applying regex separately works but how can I extract all file names regardless of format in a single search?&lt;/P&gt;
&lt;P&gt;Following works for all Windows path's but for Linux, entire path gets extracted as file_name&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;| rex field=file_path "(?P&amp;lt;file_name&amp;gt;[^\\\]+)$"&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;whereas this one works for Linux but does nothing on the Windows path.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt; | rex field=file_path ".*\/(?&amp;lt;file_name&amp;gt;.*)$"&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Is there a way to use both in same search? or a new regex that would work on either of the two formats?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 17 Apr 2023 20:20:07 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-extract-file-name-from-path-s-for-both-windows-and-nix/m-p/640246#M221856</guid>
      <dc:creator>att35</dc:creator>
      <dc:date>2023-04-17T20:20:07Z</dc:date>
    </item>
    <item>
      <title>Re: Extract file name from path's for both windows and nix format</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-extract-file-name-from-path-s-for-both-windows-and-nix/m-p/640257#M221859</link>
      <description>&lt;P&gt;This regex works in my limited testing.&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| rex field=file_path "(?&amp;lt;file_name&amp;gt;[^\/\\]+)$"&lt;/LI-CODE&gt;</description>
      <pubDate>Mon, 17 Apr 2023 17:03:14 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-extract-file-name-from-path-s-for-both-windows-and-nix/m-p/640257#M221859</guid>
      <dc:creator>richgalloway</dc:creator>
      <dc:date>2023-04-17T17:03:14Z</dc:date>
    </item>
    <item>
      <title>Re: Extract file name from path's for both windows and nix format</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-extract-file-name-from-path-s-for-both-windows-and-nix/m-p/640258#M221860</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt; | rex field=file_path "(?&amp;lt;file_name&amp;gt;[^\/\\\]+\..+)$"&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Negation for / and \, match everything that has at least one dot. Tested on:&lt;/P&gt;&lt;P&gt;C:\test\test.tst&lt;BR /&gt;/test/test/test.tst&lt;BR /&gt;/test/test/test.tst.tst&lt;/P&gt;</description>
      <pubDate>Mon, 17 Apr 2023 17:14:04 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-extract-file-name-from-path-s-for-both-windows-and-nix/m-p/640258#M221860</guid>
      <dc:creator>rut</dc:creator>
      <dc:date>2023-04-17T17:14:04Z</dc:date>
    </item>
    <item>
      <title>Re: Extract file name from path's for both windows and nix format</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-extract-file-name-from-path-s-for-both-windows-and-nix/m-p/640259#M221861</link>
      <description>&lt;P&gt;Hi&lt;/P&gt;&lt;P&gt;Is this what you are looking for?&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| makeresults 
| eval file_path="/as/bsb/asda/file.txt|c:\asda\asdadaa\aa\file.txt"
| eval file_path = split(file_path,"|")
| mvexpand file_path
``` Previous prepare sample data ```
| rex field=file_path "(?P&amp;lt;file_name&amp;gt;[^\\/\\\]+)$"&lt;/LI-CODE&gt;&lt;P&gt;r. Ismo&lt;/P&gt;</description>
      <pubDate>Mon, 17 Apr 2023 17:12:53 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-extract-file-name-from-path-s-for-both-windows-and-nix/m-p/640259#M221861</guid>
      <dc:creator>isoutamo</dc:creator>
      <dc:date>2023-04-17T17:12:53Z</dc:date>
    </item>
    <item>
      <title>Re: Extract file name from path's for both windows and nix format</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-extract-file-name-from-path-s-for-both-windows-and-nix/m-p/640268#M221864</link>
      <description>&lt;P&gt;| rex field=file_path "([^\r\n\s\\\/]+[\\\/])+(?&amp;lt;file_name&amp;gt;.*)$"&lt;/P&gt;</description>
      <pubDate>Mon, 17 Apr 2023 17:58:22 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-extract-file-name-from-path-s-for-both-windows-and-nix/m-p/640268#M221864</guid>
      <dc:creator>woodcock</dc:creator>
      <dc:date>2023-04-17T17:58:22Z</dc:date>
    </item>
  </channel>
</rss>

