<?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 a name from file location in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/extract-a-name-from-file-location/m-p/685908#M234031</link>
    <description>&lt;P&gt;Not clear what you are saying - your original post says want the word "dev", but you also want the word "env" also?&lt;/P&gt;&lt;P&gt;Is "env" something that can change?&lt;/P&gt;</description>
    <pubDate>Tue, 30 Apr 2024 01:28:47 GMT</pubDate>
    <dc:creator>bowesmana</dc:creator>
    <dc:date>2024-04-30T01:28:47Z</dc:date>
    <item>
      <title>extract a name from file location</title>
      <link>https://community.splunk.com/t5/Splunk-Search/extract-a-name-from-file-location/m-p/685898#M234024</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;How do I extract word "Dev" from below file location&lt;/P&gt;&lt;P&gt;source=/test1/folder1/scripts/monitor/log/env/dev/Error.log&lt;/P&gt;&lt;P&gt;and add some if condition statements like if word=dev,change it to development&lt;/P&gt;&lt;P&gt;word=test,change it to loadtest in splunk query.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 29 Apr 2024 23:20:00 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/extract-a-name-from-file-location/m-p/685898#M234024</guid>
      <dc:creator>guru333</dc:creator>
      <dc:date>2024-04-29T23:20:00Z</dc:date>
    </item>
    <item>
      <title>Re: extract a name from file location</title>
      <link>https://community.splunk.com/t5/Splunk-Search/extract-a-name-from-file-location/m-p/685900#M234026</link>
      <description>&lt;P&gt;Here's an example you can run in the search window - you are interested in the last two lines : rex statement and the final eval statement.&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| makeresults 
| fields - _time
| eval source=split("/test1/folder1/scripts/monitor/log/env/dev/Error.log,/test1/folder1/scripts/monitor/log/env/test/Error.log", ",")
| mvexpand source
| rex field=source ".*\/(?&amp;lt;env&amp;gt;\w+)\/.*"
| eval environment=case(env="dev","development",env="test","loadtest",true(), "unknown:".env)&lt;/LI-CODE&gt;&lt;P&gt;There are several ways you can assign the name to the environment - if you have lots of environments you can do this from a lookup or just use the case statement.&lt;/P&gt;</description>
      <pubDate>Mon, 29 Apr 2024 23:28:13 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/extract-a-name-from-file-location/m-p/685900#M234026</guid>
      <dc:creator>bowesmana</dc:creator>
      <dc:date>2024-04-29T23:28:13Z</dc:date>
    </item>
    <item>
      <title>Re: extract a name from file location</title>
      <link>https://community.splunk.com/t5/Splunk-Search/extract-a-name-from-file-location/m-p/685906#M234029</link>
      <description>&lt;P&gt;Thanks for your response&lt;/P&gt;&lt;P&gt;But my file location is&lt;/P&gt;&lt;P&gt;/test1/folder1/.scripts/monitor/log/env/dev/Error.log&lt;/P&gt;&lt;P&gt;So interested to get both values of&amp;nbsp;&lt;/P&gt;&lt;P&gt;env and dev&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 30 Apr 2024 01:10:02 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/extract-a-name-from-file-location/m-p/685906#M234029</guid>
      <dc:creator>guru333</dc:creator>
      <dc:date>2024-04-30T01:10:02Z</dc:date>
    </item>
    <item>
      <title>Re: extract a name from file location</title>
      <link>https://community.splunk.com/t5/Splunk-Search/extract-a-name-from-file-location/m-p/685908#M234031</link>
      <description>&lt;P&gt;Not clear what you are saying - your original post says want the word "dev", but you also want the word "env" also?&lt;/P&gt;&lt;P&gt;Is "env" something that can change?&lt;/P&gt;</description>
      <pubDate>Tue, 30 Apr 2024 01:28:47 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/extract-a-name-from-file-location/m-p/685908#M234031</guid>
      <dc:creator>bowesmana</dc:creator>
      <dc:date>2024-04-30T01:28:47Z</dc:date>
    </item>
    <item>
      <title>Re: extract a name from file location</title>
      <link>https://community.splunk.com/t5/Splunk-Search/extract-a-name-from-file-location/m-p/685912#M234034</link>
      <description>&lt;P&gt;yes&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;/test1/folder1/.scripts/monitor/log/env/dev/Error.log&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;I want&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;field 1=value of env&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;field 2=value of dev&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;as there is scope of this changing later.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 30 Apr 2024 01:38:57 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/extract-a-name-from-file-location/m-p/685912#M234034</guid>
      <dc:creator>guru333</dc:creator>
      <dc:date>2024-04-30T01:38:57Z</dc:date>
    </item>
    <item>
      <title>Re: extract a name from file location</title>
      <link>https://community.splunk.com/t5/Splunk-Search/extract-a-name-from-file-location/m-p/685913#M234035</link>
      <description>&lt;P class="lia-align-left"&gt;Also&lt;/P&gt;&lt;P class="lia-align-left"&gt;&amp;nbsp;&lt;/P&gt;&lt;P class="lia-align-left"&gt;/test1/folder1/scripts/monitor/log/env/dev/Error.log is dynamic source field value and not hardcoded value&amp;nbsp;/test1/folder1/scripts/monitor/log/env/dev/Error.log so I need to integrate index command with&amp;nbsp;makeresults something like this&lt;/P&gt;&lt;P class="lia-align-left"&gt;index="monitoring"&lt;/P&gt;&lt;P class="lia-align-left"&gt;source="&lt;SPAN&gt;/test1/folder1/.scripts/monitor/log/env/dev/Error.log&lt;/SPAN&gt;"&lt;/P&gt;&lt;P class="lia-align-left"&gt;extract values of env and dev...that can be dynamic to separate fields.&lt;/P&gt;</description>
      <pubDate>Tue, 30 Apr 2024 02:09:06 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/extract-a-name-from-file-location/m-p/685913#M234035</guid>
      <dc:creator>guru333</dc:creator>
      <dc:date>2024-04-30T02:09:06Z</dc:date>
    </item>
    <item>
      <title>Re: extract a name from file location</title>
      <link>https://community.splunk.com/t5/Splunk-Search/extract-a-name-from-file-location/m-p/685921#M234039</link>
      <description>&lt;P&gt;You are making lots of apparently conflicting statements. &amp;nbsp;It is important to illustrate/supplement your problem with sample/mock data and desired results, as well as a plain language statement of the logic between illustrated data and desired results. &amp;nbsp;Can you confirm that you are looking for results like&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;dev&lt;/TD&gt;&lt;TD&gt;env&lt;/TD&gt;&lt;TD&gt;source&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;dev11&lt;/TD&gt;&lt;TD&gt;env11&lt;/TD&gt;&lt;TD&gt;/test1/folder1/scripts/monitor/log/env11/dev11/Error.log&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;dev21&lt;/TD&gt;&lt;TD&gt;env21&lt;/TD&gt;&lt;TD&gt;/test2/folder1/scripts/monitor/log/env21/dev21/Error.log&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;In other words, you want the second-to-last segment of the path to be in a field (named &lt;EM&gt;dev&lt;/EM&gt;) and the 3rd-to-last segment to be in another field (named &lt;EM&gt;env&lt;/EM&gt;).&lt;/P&gt;&lt;P&gt;If my mind-reading is correct, you can use the following&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| eval mvsource = split(source, "/")
| eval env = mvindex(mvsource, -3), dev = mvindex(mvsource, -2)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This is the emulation I use to produce the sample data&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| makeresults format=csv data="source
/test1/folder1/scripts/monitor/log/env11/dev11/Error.log
/test2/folder1/scripts/monitor/log/env21/dev21/Error.log"
``` data emulation above ```&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Play with it and compare with real data&lt;/P&gt;</description>
      <pubDate>Tue, 30 Apr 2024 05:46:17 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/extract-a-name-from-file-location/m-p/685921#M234039</guid>
      <dc:creator>yuanliu</dc:creator>
      <dc:date>2024-04-30T05:46:17Z</dc:date>
    </item>
    <item>
      <title>Re: extract a name from file location</title>
      <link>https://community.splunk.com/t5/Splunk-Search/extract-a-name-from-file-location/m-p/685927#M234041</link>
      <description>&lt;P&gt;When someone provides you an example using the makeresults command, it is an example you can run to DEMONSTRATE the solution - in my posting I showed the example and said you need the last two lines.&lt;/P&gt;&lt;P&gt;The rex statement extracts fields from data. This will extract "env" and "dev" into fields a and b. Call them what you like&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| rex field=source ".*\/(?&amp;lt;a&amp;gt;\w+)\/(?&amp;lt;b&amp;gt;\w+)\/.*"&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 30 Apr 2024 07:42:07 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/extract-a-name-from-file-location/m-p/685927#M234041</guid>
      <dc:creator>bowesmana</dc:creator>
      <dc:date>2024-04-30T07:42:07Z</dc:date>
    </item>
  </channel>
</rss>

