<?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: Can you help me extract a filename from a filepath in a field transformation? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Can-you-help-me-extract-a-filename-from-a-filepath-in-a-field/m-p/381991#M111668</link>
    <description>&lt;P&gt;You can try below transform as it takes very less steps:-&lt;/P&gt;

&lt;P&gt;\D*\(?\w*.\w*)&lt;/P&gt;</description>
    <pubDate>Tue, 29 Sep 2020 23:18:29 GMT</pubDate>
    <dc:creator>kushagra9120</dc:creator>
    <dc:date>2020-09-29T23:18:29Z</dc:date>
    <item>
      <title>Can you help me extract a filename from a filepath in a field transformation?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Can-you-help-me-extract-a-filename-from-a-filepath-in-a-field/m-p/381984#M111661</link>
      <description>&lt;P&gt;I have a path (and a variable file_path) that looks like this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;C:\\\\Program Files\\\\theapp\\\\the app\\\\Tools\\\\IR\\\\somefolder\\\\somefile.exe
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;And I'm trying to retrieve the file name &lt;CODE&gt;somefile.exe&lt;/CODE&gt;&lt;/P&gt;

&lt;P&gt;I created a Field transformation with the following info, but I'm not getting the field file_name to populate&lt;/P&gt;

&lt;P&gt;name: &lt;CODE&gt;file_name&lt;/CODE&gt;&lt;/P&gt;

&lt;P&gt;Regular expression: &lt;CODE&gt;(?P&amp;lt;file_name&amp;gt;[^\\]+)$&lt;/CODE&gt;&lt;/P&gt;

&lt;P&gt;Format:&lt;/P&gt;

&lt;P&gt;Source Key: &lt;CODE&gt;file_path&lt;/CODE&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 13 Feb 2019 18:13:37 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Can-you-help-me-extract-a-filename-from-a-filepath-in-a-field/m-p/381984#M111661</guid>
      <dc:creator>mkarimi17</dc:creator>
      <dc:date>2019-02-13T18:13:37Z</dc:date>
    </item>
    <item>
      <title>Re: Can you help me extract a filename from a filepath in a field transformation?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Can-you-help-me-extract-a-filename-from-a-filepath-in-a-field/m-p/381985#M111662</link>
      <description>&lt;P&gt;Hello @mkarimi17,&lt;/P&gt;

&lt;P&gt;I just tested this out using the event source=C:\Program Files\SplunkUniversalForwarder\var\log\splunk\splunkd.log.&lt;/P&gt;

&lt;P&gt;I needed 4 backslashes in the regex to get it working:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;source="C:\\Program Files\\SplunkUniversalForwarder\\var\\log\\splunk\\splunkd.log"
| rex field=source "(?&amp;lt;file_name&amp;gt;[^\\\\]+)$"
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 13 Feb 2019 19:21:33 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Can-you-help-me-extract-a-filename-from-a-filepath-in-a-field/m-p/381985#M111662</guid>
      <dc:creator>whrg</dc:creator>
      <dc:date>2019-02-13T19:21:33Z</dc:date>
    </item>
    <item>
      <title>Re: Can you help me extract a filename from a filepath in a field transformation?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Can-you-help-me-extract-a-filename-from-a-filepath-in-a-field/m-p/381986#M111663</link>
      <description>&lt;P&gt;Like this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| makeresults 
| eval file_path=" C:\\\\\\\\Program Files\\\\\\\\theapp\\\\\\\\the app\\\\\\\\Tools\\\\\\\\IR\\\\\\\\somefolder\\\\\\\\somefile.exe"
| rex field=file_path "(?&amp;lt;file_name&amp;gt;[^\\\]+)$"
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 13 Feb 2019 19:41:30 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Can-you-help-me-extract-a-filename-from-a-filepath-in-a-field/m-p/381986#M111663</guid>
      <dc:creator>woodcock</dc:creator>
      <dc:date>2019-02-13T19:41:30Z</dc:date>
    </item>
    <item>
      <title>Re: Can you help me extract a filename from a filepath in a field transformation?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Can-you-help-me-extract-a-filename-from-a-filepath-in-a-field/m-p/381987#M111664</link>
      <description>&lt;P&gt;The thing is my regex works when I test it, but it doesn't work when I create the file transformation.  For example, when I type yours in I get:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;Encountered the following error while trying to update: Regex: missing terminating ] for character class
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 13 Feb 2019 19:48:40 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Can-you-help-me-extract-a-filename-from-a-filepath-in-a-field/m-p/381987#M111664</guid>
      <dc:creator>mkarimi17</dc:creator>
      <dc:date>2019-02-13T19:48:40Z</dc:date>
    </item>
    <item>
      <title>Re: Can you help me extract a filename from a filepath in a field transformation?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Can-you-help-me-extract-a-filename-from-a-filepath-in-a-field/m-p/381988#M111665</link>
      <description>&lt;P&gt;Ah, right, when putting it into files, you need to adjust the backslashes; use this instead:&lt;/P&gt;

&lt;P&gt;In props.conf:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;[YourSourcetypeHere]
REPORT-file_name_FROM_file_path
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;In transforms.conf:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;[file_name_FROM_file_path]
REGEX = ([^\\]+)$
SOURCE_KEY = file_path
FORMAT = file_name::$1
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Capitalization is CRITICAL.  Also, note that you probably need &lt;CODE&gt;REPORT-&lt;/CODE&gt; (for search-time extractions) instead of &lt;CODE&gt;TRANSFORMS-&lt;/CODE&gt; (for index-time extractions) because I am pretty sure that the &lt;CODE&gt;file_path&lt;/CODE&gt; field is not an index-time field.&lt;/P&gt;</description>
      <pubDate>Wed, 13 Feb 2019 20:03:02 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Can-you-help-me-extract-a-filename-from-a-filepath-in-a-field/m-p/381988#M111665</guid>
      <dc:creator>woodcock</dc:creator>
      <dc:date>2019-02-13T20:03:02Z</dc:date>
    </item>
    <item>
      <title>Re: Can you help me extract a filename from a filepath in a field transformation?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Can-you-help-me-extract-a-filename-from-a-filepath-in-a-field/m-p/381989#M111666</link>
      <description>&lt;P&gt;Does it make a difference if I'm doing this on the search head using the field transformation option under "Fields"? My Splunk searchhead is in the cloud so I don't have access to the files. &lt;/P&gt;</description>
      <pubDate>Wed, 13 Feb 2019 21:33:32 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Can-you-help-me-extract-a-filename-from-a-filepath-in-a-field/m-p/381989#M111666</guid>
      <dc:creator>mkarimi17</dc:creator>
      <dc:date>2019-02-13T21:33:32Z</dc:date>
    </item>
    <item>
      <title>Re: Can you help me extract a filename from a filepath in a field transformation?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Can-you-help-me-extract-a-filename-from-a-filepath-in-a-field/m-p/381990#M111667</link>
      <description>&lt;P&gt;No, it should work exactly the same.  These settings will do what you need.&lt;/P&gt;</description>
      <pubDate>Wed, 13 Feb 2019 22:18:41 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Can-you-help-me-extract-a-filename-from-a-filepath-in-a-field/m-p/381990#M111667</guid>
      <dc:creator>woodcock</dc:creator>
      <dc:date>2019-02-13T22:18:41Z</dc:date>
    </item>
    <item>
      <title>Re: Can you help me extract a filename from a filepath in a field transformation?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Can-you-help-me-extract-a-filename-from-a-filepath-in-a-field/m-p/381991#M111668</link>
      <description>&lt;P&gt;You can try below transform as it takes very less steps:-&lt;/P&gt;

&lt;P&gt;\D*\(?\w*.\w*)&lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2020 23:18:29 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Can-you-help-me-extract-a-filename-from-a-filepath-in-a-field/m-p/381991#M111668</guid>
      <dc:creator>kushagra9120</dc:creator>
      <dc:date>2020-09-29T23:18:29Z</dc:date>
    </item>
    <item>
      <title>Re: Can you help me extract a filename from a filepath in a field transformation?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Can-you-help-me-extract-a-filename-from-a-filepath-in-a-field/m-p/381992#M111669</link>
      <description>&lt;P&gt;Are you putting this into transforms.conf?  If so, then you need to remove one of the back-slashes, like this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;REGEX = (?&amp;lt;file_name&amp;gt;[^\\]+)$
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 06 Mar 2019 08:40:31 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Can-you-help-me-extract-a-filename-from-a-filepath-in-a-field/m-p/381992#M111669</guid>
      <dc:creator>woodcock</dc:creator>
      <dc:date>2019-03-06T08:40:31Z</dc:date>
    </item>
  </channel>
</rss>

