<?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 to create a conditional rex statement on file extension or directory? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-to-create-a-conditional-rex-statement-on-file-extension-or/m-p/479856#M134483</link>
    <description>&lt;P&gt;Please share some sample data and desired extractions.&lt;/P&gt;</description>
    <pubDate>Thu, 23 Apr 2020 17:20:41 GMT</pubDate>
    <dc:creator>richgalloway</dc:creator>
    <dc:date>2020-04-23T17:20:41Z</dc:date>
    <item>
      <title>How to create a conditional rex statement on file extension or directory?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-create-a-conditional-rex-statement-on-file-extension-or/m-p/479855#M134482</link>
      <description>&lt;P&gt;I'm trying to figure out how to do a conditional rex statement that looks at a windows file path and determines if the last segment of the path has a ., it creates a field called extension, but if it doesn't end with an extension, it creates a field called directory and puts the full value (with spaces) of the last directory in the segment. Is there a way to do a conditional statement like this with rex?&lt;/P&gt;</description>
      <pubDate>Thu, 23 Apr 2020 17:04:58 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-create-a-conditional-rex-statement-on-file-extension-or/m-p/479855#M134482</guid>
      <dc:creator>mjones414</dc:creator>
      <dc:date>2020-04-23T17:04:58Z</dc:date>
    </item>
    <item>
      <title>Re: How to create a conditional rex statement on file extension or directory?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-create-a-conditional-rex-statement-on-file-extension-or/m-p/479856#M134483</link>
      <description>&lt;P&gt;Please share some sample data and desired extractions.&lt;/P&gt;</description>
      <pubDate>Thu, 23 Apr 2020 17:20:41 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-create-a-conditional-rex-statement-on-file-extension-or/m-p/479856#M134483</guid>
      <dc:creator>richgalloway</dc:creator>
      <dc:date>2020-04-23T17:20:41Z</dc:date>
    </item>
    <item>
      <title>Re: How to create a conditional rex statement on file extension or directory?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-create-a-conditional-rex-statement-on-file-extension-or/m-p/479857#M134484</link>
      <description>&lt;P&gt;Surely &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;

&lt;P&gt;FieldName=Object&lt;/P&gt;

&lt;P&gt;Value Examples:&lt;BR /&gt;
c:\test directory with spaces\test_directory_with_underscores\filename (with: horrible habits).txt&lt;BR /&gt;
c:\test directory with spaces\test_directory_with_underscores\little-child-directory&lt;/P&gt;

&lt;P&gt;Simple rex to get file extension:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| rex field="object" "\.(?&amp;lt;extension&amp;gt;[^\.]*$)"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;extension:&lt;BR /&gt;
txt&lt;/P&gt;

&lt;P&gt;(if extension is null, delimit by the last backslash .*$ and create a field called Directory with the value)&lt;/P&gt;

&lt;P&gt;Directory:&lt;BR /&gt;
 (want this to be little-child-directory)&lt;/P&gt;</description>
      <pubDate>Wed, 30 Sep 2020 05:05:19 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-create-a-conditional-rex-statement-on-file-extension-or/m-p/479857#M134484</guid>
      <dc:creator>mjones414</dc:creator>
      <dc:date>2020-09-30T05:05:19Z</dc:date>
    </item>
    <item>
      <title>Re: How to create a conditional rex statement on file extension or directory?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-create-a-conditional-rex-statement-on-file-extension-or/m-p/479858#M134485</link>
      <description>&lt;P&gt;Given your question and the data that you have provided, I think that this "run anywhere" search shows a &lt;CODE&gt;rex&lt;/CODE&gt; that will work as you have requested:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| makeresults | eval data="c:\test directory with spaces\test_directory_with_underscores\filename (with: horrible habits).txt|c:\test directory with spaces\test_directory_with_underscores\little-child-directory" 
| makemv delim="|" data
| mvexpand data 
| rex field=data "(\.(?&amp;lt;ext&amp;gt;[^.]+)|\\\(?&amp;lt;dir&amp;gt;[^.\\\]+))$"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;This rex requires some additional backslashes to make it interpret the backslashes that might appear on the file path, but it clearly shows that you can get one or the other of the fields that you want to extract from the data. The first three lines are just setting up the data, and the last one (with the &lt;CODE&gt;rex&lt;/CODE&gt; command) is the one with all the magic.&lt;/P&gt;</description>
      <pubDate>Thu, 23 Apr 2020 19:08:46 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-create-a-conditional-rex-statement-on-file-extension-or/m-p/479858#M134485</guid>
      <dc:creator>cpetterborg</dc:creator>
      <dc:date>2020-04-23T19:08:46Z</dc:date>
    </item>
  </channel>
</rss>

