<?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 modify my rex command to remove directory location from path? in Getting Data In</title>
    <link>https://community.splunk.com/t5/Getting-Data-In/How-do-I-modify-my-rex-command-to-remove-directory-location-from/m-p/679687#M113580</link>
    <description>&lt;P&gt;This question better belongs to&amp;nbsp;&lt;A href="https://community.splunk.com/t5/Splunk-Search/bd-p/splunk-search" target="_blank"&gt;Splunk Search&lt;/A&gt;. &amp;nbsp;Anyway, let me generalize your ask: You want the last part of the file path (which is usually file name). &amp;nbsp;You can use regex. &amp;nbsp;But a more semantic and potentially cheaper solution is to use split and mvindex.&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;EventCode=1004
| rex field=_raw "Files: (?&amp;lt;Media_Source&amp;gt;.+?\.txt)"
| table Media_Source
| eval Filename = mvindex(split(Media_Source, "\"), -1)&lt;/LI-CODE&gt;&lt;P&gt;If you really want to use regex, you can do&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;EventCode=1004
| rex field=_raw "Files: .+?\\(?&amp;lt;Media_Source&amp;gt;[^\\]+\.txt)" 
| table Media_Source&lt;/LI-CODE&gt;&lt;P&gt;Hope this helps.&lt;/P&gt;</description>
    <pubDate>Wed, 06 Mar 2024 02:01:13 GMT</pubDate>
    <dc:creator>yuanliu</dc:creator>
    <dc:date>2024-03-06T02:01:13Z</dc:date>
    <item>
      <title>How do I modify my rex command to remove directory location from path?</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/How-do-I-modify-my-rex-command-to-remove-directory-location-from/m-p/679647#M113579</link>
      <description>&lt;P&gt;Here is my current rex command -&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;EventCode=1004
| rex field=_raw "Files: (?&amp;lt;Media_Source&amp;gt;.+?\.txt)" 
| table Media_Source&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;My source data looks like this -&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;Files: C:\ProgramData\Roxio Log Files\Test.test_user_20240305122549.txt SHA1: 73b710056457bd9bda5fee22bb2a2ada8aa9f3e0&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;My current rex result is -&amp;nbsp;&amp;nbsp;C:\ProgramData\Roxio Log Files\Test.test_user_20240305122549.txt&lt;/P&gt;&lt;P&gt;How do I make it -&amp;nbsp;Test.test_user_20240305122549.txt&lt;/P&gt;&lt;P&gt;Im trying to drop -&amp;nbsp;C:\ProgramData\Roxio Log Files\&lt;/P&gt;</description>
      <pubDate>Tue, 05 Mar 2024 20:14:02 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/How-do-I-modify-my-rex-command-to-remove-directory-location-from/m-p/679647#M113579</guid>
      <dc:creator>jeradb</dc:creator>
      <dc:date>2024-03-05T20:14:02Z</dc:date>
    </item>
    <item>
      <title>Re: How do I modify my rex command to remove directory location from path?</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/How-do-I-modify-my-rex-command-to-remove-directory-location-from/m-p/679687#M113580</link>
      <description>&lt;P&gt;This question better belongs to&amp;nbsp;&lt;A href="https://community.splunk.com/t5/Splunk-Search/bd-p/splunk-search" target="_blank"&gt;Splunk Search&lt;/A&gt;. &amp;nbsp;Anyway, let me generalize your ask: You want the last part of the file path (which is usually file name). &amp;nbsp;You can use regex. &amp;nbsp;But a more semantic and potentially cheaper solution is to use split and mvindex.&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;EventCode=1004
| rex field=_raw "Files: (?&amp;lt;Media_Source&amp;gt;.+?\.txt)"
| table Media_Source
| eval Filename = mvindex(split(Media_Source, "\"), -1)&lt;/LI-CODE&gt;&lt;P&gt;If you really want to use regex, you can do&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;EventCode=1004
| rex field=_raw "Files: .+?\\(?&amp;lt;Media_Source&amp;gt;[^\\]+\.txt)" 
| table Media_Source&lt;/LI-CODE&gt;&lt;P&gt;Hope this helps.&lt;/P&gt;</description>
      <pubDate>Wed, 06 Mar 2024 02:01:13 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/How-do-I-modify-my-rex-command-to-remove-directory-location-from/m-p/679687#M113580</guid>
      <dc:creator>yuanliu</dc:creator>
      <dc:date>2024-03-06T02:01:13Z</dc:date>
    </item>
  </channel>
</rss>

