<?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 How to Rex out junk in a file path? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-to-Rex-out-junk-in-a-file-path/m-p/261642#M78537</link>
    <description>&lt;P&gt;Scenario:&lt;BR /&gt;
I have the following field called 'filePath'&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;/src/lkfdjgsryj3kt4z57RdC-1-SomeDocument.doc 
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;I would like to strip off everything in front of the file (called SomeDocument). The common pattern is the "-1-".&lt;/P&gt;

&lt;P&gt;I have had no luck with my newbie REX attempts.&lt;/P&gt;

&lt;P&gt;Thank you for your help.&lt;/P&gt;</description>
    <pubDate>Mon, 23 May 2016 18:53:24 GMT</pubDate>
    <dc:creator>packet_hunter</dc:creator>
    <dc:date>2016-05-23T18:53:24Z</dc:date>
    <item>
      <title>How to Rex out junk in a file path?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-Rex-out-junk-in-a-file-path/m-p/261642#M78537</link>
      <description>&lt;P&gt;Scenario:&lt;BR /&gt;
I have the following field called 'filePath'&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;/src/lkfdjgsryj3kt4z57RdC-1-SomeDocument.doc 
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;I would like to strip off everything in front of the file (called SomeDocument). The common pattern is the "-1-".&lt;/P&gt;

&lt;P&gt;I have had no luck with my newbie REX attempts.&lt;/P&gt;

&lt;P&gt;Thank you for your help.&lt;/P&gt;</description>
      <pubDate>Mon, 23 May 2016 18:53:24 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-Rex-out-junk-in-a-file-path/m-p/261642#M78537</guid>
      <dc:creator>packet_hunter</dc:creator>
      <dc:date>2016-05-23T18:53:24Z</dc:date>
    </item>
    <item>
      <title>Re: How to Rex out junk in a file path?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-Rex-out-junk-in-a-file-path/m-p/261643#M78538</link>
      <description>&lt;P&gt;This should do it.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;"-1-(?&amp;lt;filename&amp;gt;.*)"
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 23 May 2016 19:03:13 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-Rex-out-junk-in-a-file-path/m-p/261643#M78538</guid>
      <dc:creator>richgalloway</dc:creator>
      <dc:date>2016-05-23T19:03:13Z</dc:date>
    </item>
    <item>
      <title>Re: How to Rex out junk in a file path?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-Rex-out-junk-in-a-file-path/m-p/261644#M78539</link>
      <description>&lt;PRE&gt;&lt;CODE&gt; ... | rex "-1-(?&amp;lt;fileName&amp;gt;.*)" | table fileName
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 23 May 2016 19:03:50 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-Rex-out-junk-in-a-file-path/m-p/261644#M78539</guid>
      <dc:creator>jkat54</dc:creator>
      <dc:date>2016-05-23T19:03:50Z</dc:date>
    </item>
    <item>
      <title>Re: How to Rex out junk in a file path?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-Rex-out-junk-in-a-file-path/m-p/261645#M78540</link>
      <description>&lt;P&gt;This will do it&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;your base search | rex field=filePath mode=sed "s/(.*)\/(\w+)-1-(.+)$/\1\/\3/g" 
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;OR&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;your base search | eval filePath=replace(filePath,"(.*)\/(\w+)-1-(.+)","\1\/\3") 
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;&lt;STRONG&gt;UPdated&lt;/STRONG&gt; &lt;BR /&gt;
Try any of these&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| eval filePath=replace(filePath,"(.*)\/([^\/-]+)(\/|-)(.+)","\1/\4")  
| rex field=filePath mode=sed "s/(.*)\/([^\/-]+)(\/|-)(.+)$/\1\/\4/g"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;&lt;STRONG&gt;Update#2&lt;/STRONG&gt;&lt;/P&gt;

&lt;P&gt;I did read the question wrong and was trying to retain first portion of the path. Apart from other answers you got, these are additional way to doing the same. Lines before the last line is to generate the sample data.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| gentimes start=-1 | eval filePath="/src/lkfdjgsryj3kt4z57RdC-1-SomeDocument.doc#/src/lkfdjgsryj3kt4z57RdC/SomeDocument.doc#/lkfdjgsryj3kt4z57RdC-1-SomeDocument.doc#/src/temp/lkfdjgsryj3kt4z57RdC-1-SomeDocument.doc" | table filePath | makemv filePath delim="#" | mvexpand filePath  | eval orig=filePath
| eval filePath1=replace(filePath,"(.*)(\/|-)(\w+\.\w+)$","\3")  | rex field=filePath mode=sed "s/(.*)(\/|-)(\w+\.\w+)$/\3/g"
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 23 May 2016 19:11:43 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-Rex-out-junk-in-a-file-path/m-p/261645#M78540</guid>
      <dc:creator>somesoni2</dc:creator>
      <dc:date>2016-05-23T19:11:43Z</dc:date>
    </item>
    <item>
      <title>Re: How to Rex out junk in a file path?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-Rex-out-junk-in-a-file-path/m-p/261646#M78541</link>
      <description>&lt;P&gt;Thank you for the reply, I appreciate your attempt, but answer does not work for this situation. &lt;/P&gt;</description>
      <pubDate>Wed, 25 May 2016 15:43:02 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-Rex-out-junk-in-a-file-path/m-p/261646#M78541</guid>
      <dc:creator>packet_hunter</dc:creator>
      <dc:date>2016-05-25T15:43:02Z</dc:date>
    </item>
    <item>
      <title>Re: How to Rex out junk in a file path?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-Rex-out-junk-in-a-file-path/m-p/261647#M78542</link>
      <description>&lt;P&gt;Thank you for the reply, I appreciate your attempt, but answer does not work for this situation. &lt;/P&gt;</description>
      <pubDate>Wed, 25 May 2016 15:43:28 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-Rex-out-junk-in-a-file-path/m-p/261647#M78542</guid>
      <dc:creator>packet_hunter</dc:creator>
      <dc:date>2016-05-25T15:43:28Z</dc:date>
    </item>
    <item>
      <title>Re: How to Rex out junk in a file path?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-Rex-out-junk-in-a-file-path/m-p/261648#M78543</link>
      <description>&lt;P&gt;Why not?  It works with your sample data.  Please show the query you're using and we may be able to help get it working.&lt;/P&gt;</description>
      <pubDate>Wed, 25 May 2016 15:47:27 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-Rex-out-junk-in-a-file-path/m-p/261648#M78543</guid>
      <dc:creator>richgalloway</dc:creator>
      <dc:date>2016-05-25T15:47:27Z</dc:date>
    </item>
    <item>
      <title>Re: How to Rex out junk in a file path?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-Rex-out-junk-in-a-file-path/m-p/261649#M78544</link>
      <description>&lt;P&gt;Thank you for the reply.   Both work well, however I have to make my question a bit more challenging now.&lt;BR /&gt;
I am now seeing data come in that is not all the same.&lt;BR /&gt;
For example: &lt;BR /&gt;
/src/lkfdjgsryj3kt4z57RdC-1-SomeDocument.doc &lt;BR /&gt;
/src/lkfdjgsryj3kt4z57RdC/SomeDocument.doc &lt;/P&gt;

&lt;P&gt;Notice the character before the document is either [/] or [-].&lt;/P&gt;

&lt;P&gt;is it possible rex / eval from the end?   &lt;/P&gt;

&lt;P&gt;For example include everything before and after the [.] but drop everything after [/] or [-] ?  the result being &lt;BR /&gt;
SomeDocument.extn&lt;/P&gt;

&lt;P&gt;Thank you&lt;/P&gt;</description>
      <pubDate>Wed, 25 May 2016 15:50:52 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-Rex-out-junk-in-a-file-path/m-p/261649#M78544</guid>
      <dc:creator>packet_hunter</dc:creator>
      <dc:date>2016-05-25T15:50:52Z</dc:date>
    </item>
    <item>
      <title>Re: How to Rex out junk in a file path?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-Rex-out-junk-in-a-file-path/m-p/261650#M78545</link>
      <description>&lt;P&gt;Based on your latest comment to somesoni2 and assuming a filename is always alphnumeric, this rex command will generate a new field called 'filename' with desired part of filePath.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;... | rex field=filePath "(?&amp;lt;=\/|-1-)(?&amp;lt;filename&amp;gt;\w+\.\w+)" | ...
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 25 May 2016 15:57:43 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-Rex-out-junk-in-a-file-path/m-p/261650#M78545</guid>
      <dc:creator>richgalloway</dc:creator>
      <dc:date>2016-05-25T15:57:43Z</dc:date>
    </item>
    <item>
      <title>Re: How to Rex out junk in a file path?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-Rex-out-junk-in-a-file-path/m-p/261651#M78546</link>
      <description>&lt;P&gt;Try the updated answer.&lt;/P&gt;</description>
      <pubDate>Wed, 25 May 2016 15:59:42 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-Rex-out-junk-in-a-file-path/m-p/261651#M78546</guid>
      <dc:creator>somesoni2</dc:creator>
      <dc:date>2016-05-25T15:59:42Z</dc:date>
    </item>
    <item>
      <title>Re: How to Rex out junk in a file path?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-Rex-out-junk-in-a-file-path/m-p/261652#M78547</link>
      <description>&lt;P&gt;Not quite perfected  &lt;/P&gt;

&lt;P&gt;other sample data before &amp;gt; after&lt;/P&gt;

&lt;P&gt;/src/474702523/xtract/SomeDocument.doc &amp;gt; /src/474702523/Information.doc &lt;BR /&gt;
/3rBN0S5Z7Cz5dG9K-1-SomeDocument.zip &amp;gt; /1-Information.zip&lt;/P&gt;

&lt;P&gt;here is the code I am using by the way, maybe I am jacking something up...&lt;/P&gt;

&lt;P&gt;index=main sourcetype=X_cef_syslog eventtype=X | [your code inserted] |  stats list(filePath)&lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2020 09:45:35 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-Rex-out-junk-in-a-file-path/m-p/261652#M78547</guid>
      <dc:creator>packet_hunter</dc:creator>
      <dc:date>2020-09-29T09:45:35Z</dc:date>
    </item>
    <item>
      <title>Re: How to Rex out junk in a file path?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-Rex-out-junk-in-a-file-path/m-p/261653#M78548</link>
      <description>&lt;P&gt;This is what I tried &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=main sourcetype=X_cef_syslog eventtype=X  |  rex field=filePath  "-1-(?&amp;lt;filename&amp;gt;.*)"  | stats list(filePath)

index=main sourcetype=X_cef_syslog eventtype=X  |  rex field=filePath "(?&amp;lt;=\/|-1-)(?&amp;lt;filename&amp;gt;\w+\.\w+)"   | stats list(filePath)
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;I am probably not doing something right, the problem is not knowing what to ask you guys, I am sure your code would work in other situations, maybe its my data.&lt;/P&gt;

&lt;P&gt;I appreciate your help.&lt;/P&gt;</description>
      <pubDate>Wed, 25 May 2016 17:33:14 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-Rex-out-junk-in-a-file-path/m-p/261653#M78548</guid>
      <dc:creator>packet_hunter</dc:creator>
      <dc:date>2016-05-25T17:33:14Z</dc:date>
    </item>
    <item>
      <title>Re: How to Rex out junk in a file path?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-Rex-out-junk-in-a-file-path/m-p/261654#M78549</link>
      <description>&lt;P&gt;d'oh I changed to filePath to filename it works great!!!&lt;/P&gt;

&lt;P&gt;Sorry for the extra confusion.&lt;/P&gt;

&lt;P&gt;Thank you!&lt;/P&gt;</description>
      <pubDate>Wed, 25 May 2016 17:41:04 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-Rex-out-junk-in-a-file-path/m-p/261654#M78549</guid>
      <dc:creator>packet_hunter</dc:creator>
      <dc:date>2016-05-25T17:41:04Z</dc:date>
    </item>
    <item>
      <title>Re: How to Rex out junk in a file path?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-Rex-out-junk-in-a-file-path/m-p/261655#M78550</link>
      <description>&lt;P&gt;If you have time to update this, I do learn from examples.   I will also play around with this code and post an update if I can get it to work.&lt;/P&gt;

&lt;P&gt;Thank you!!!&lt;/P&gt;</description>
      <pubDate>Wed, 25 May 2016 17:45:46 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-Rex-out-junk-in-a-file-path/m-p/261655#M78550</guid>
      <dc:creator>packet_hunter</dc:creator>
      <dc:date>2016-05-25T17:45:46Z</dc:date>
    </item>
    <item>
      <title>Re: How to Rex out junk in a file path?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-Rex-out-junk-in-a-file-path/m-p/261656#M78551</link>
      <description>&lt;P&gt;Correction, your code is correct.  It was my error.   Thank you for your response. &lt;/P&gt;</description>
      <pubDate>Wed, 25 May 2016 17:47:38 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-Rex-out-junk-in-a-file-path/m-p/261656#M78551</guid>
      <dc:creator>packet_hunter</dc:creator>
      <dc:date>2016-05-25T17:47:38Z</dc:date>
    </item>
    <item>
      <title>Re: How to Rex out junk in a file path?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-Rex-out-junk-in-a-file-path/m-p/261657#M78552</link>
      <description>&lt;P&gt;As you were first with a correct answer, I will accept your answer.   Thank you.&lt;/P&gt;

&lt;P&gt;And thanks to everyone who helped find an answer.&lt;/P&gt;</description>
      <pubDate>Wed, 25 May 2016 17:49:00 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-Rex-out-junk-in-a-file-path/m-p/261657#M78552</guid>
      <dc:creator>packet_hunter</dc:creator>
      <dc:date>2016-05-25T17:49:00Z</dc:date>
    </item>
    <item>
      <title>Re: How to Rex out junk in a file path?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-Rex-out-junk-in-a-file-path/m-p/261658#M78553</link>
      <description>&lt;P&gt;Please accept an answer.&lt;/P&gt;</description>
      <pubDate>Wed, 25 May 2016 17:49:09 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-Rex-out-junk-in-a-file-path/m-p/261658#M78553</guid>
      <dc:creator>richgalloway</dc:creator>
      <dc:date>2016-05-25T17:49:09Z</dc:date>
    </item>
    <item>
      <title>Re: How to Rex out junk in a file path?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-Rex-out-junk-in-a-file-path/m-p/261659#M78554</link>
      <description>&lt;PRE&gt;&lt;CODE&gt;¯\_(ツ)_/¯
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 25 May 2016 18:03:11 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-Rex-out-junk-in-a-file-path/m-p/261659#M78554</guid>
      <dc:creator>jkat54</dc:creator>
      <dc:date>2016-05-25T18:03:11Z</dc:date>
    </item>
  </channel>
</rss>

