<?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: Field extraction from source field in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Field-extraction-from-source-field/m-p/389792#M113573</link>
    <description>&lt;P&gt;Hi&lt;/P&gt;

&lt;P&gt;Try this&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| makeresults 
 | eval source = "source=/default/folder/20190402/file_EMEA_IRE_DUB_8964_txt" 
 | rex field=source "file\_(?P&amp;lt;name&amp;gt;.+)_\d+"
&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Wed, 03 Apr 2019 16:28:40 GMT</pubDate>
    <dc:creator>vnravikumar</dc:creator>
    <dc:date>2019-04-03T16:28:40Z</dc:date>
    <item>
      <title>Field extraction from source field</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Field-extraction-from-source-field/m-p/389786#M113567</link>
      <description>&lt;P&gt;I have my Splunk source in the format below :&lt;/P&gt;

&lt;P&gt;source=/default/folder/20190403/file_PARADOX_7747_txt&lt;/P&gt;

&lt;P&gt;I am trying to only pick the file name from the source to do some analysis &amp;amp; unable to get rid of unwanted process id appended at the end i.e., I only need PARADOX from the above. &lt;/P&gt;

&lt;P&gt;Below is the closest I have got so far , however I am unable to separate the process id from the file name&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;rex field=source "(?&amp;lt;logdir&amp;gt;[\w\W/]+)/file_(?&amp;lt;filename&amp;gt;[^.]+)_txt"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;UL&gt;
&lt;LI&gt;logdir : /default/folder/20190403/&lt;/LI&gt;
&lt;LI&gt;filename : PARADOX_7747&lt;/LI&gt;
&lt;/UL&gt;

&lt;P&gt;Ideally, I  would like the below output :&lt;/P&gt;

&lt;UL&gt;
&lt;LI&gt;logdir : /default/folder/&lt;/LI&gt;
&lt;LI&gt;date : 20190403&lt;/LI&gt;
&lt;LI&gt;processid : 7747&lt;/LI&gt;
&lt;LI&gt;filename : PARADOX&lt;/LI&gt;
&lt;LI&gt;extension : txt&lt;/LI&gt;
&lt;/UL&gt;

&lt;P&gt;Any help is appreciated . Thank you.&lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2020 23:56:28 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Field-extraction-from-source-field/m-p/389786#M113567</guid>
      <dc:creator>ppatkar</dc:creator>
      <dc:date>2020-09-29T23:56:28Z</dc:date>
    </item>
    <item>
      <title>Re: Field extraction from source field</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Field-extraction-from-source-field/m-p/389787#M113568</link>
      <description>&lt;P&gt;You were pretty close. I guess this should work (unless the filename can also contain _ or other variations on the format cause this to break in some cases.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| rex field=source "(?&amp;lt;logdir&amp;gt;[\w\W/]+)/file_(?&amp;lt;filename&amp;gt;[^_]+)_(?&amp;lt;processid&amp;gt;[^_]+)_txt"
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 03 Apr 2019 14:29:12 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Field-extraction-from-source-field/m-p/389787#M113568</guid>
      <dc:creator>FrankVl</dc:creator>
      <dc:date>2019-04-03T14:29:12Z</dc:date>
    </item>
    <item>
      <title>Re: Field extraction from source field</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Field-extraction-from-source-field/m-p/389788#M113569</link>
      <description>&lt;P&gt;Hi&lt;/P&gt;

&lt;P&gt;Give a try&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| makeresults 
| eval source = "/default/folder/20190403/file_PARADOX_7747_txt" 
| eval filename = mvindex(split(source,"_"),1)
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;OR&lt;/P&gt;

&lt;P&gt;To avoid any directory  that contains the underscore&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| makeresults 
| eval source = "/default/folder/20190403/file_PARADOX_7747_txt" 
| rex field=source "\/(?P&amp;lt;filename&amp;gt;file.+)" 
| eval filename = mvindex(split(filename,"_"),1)
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;[New]:&lt;/P&gt;

&lt;P&gt;Try this&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| makeresults 
 | eval source = "/default/folder/20190402/file_AMR_CA_1234_txt" 
 | rex field=source "file\_(?P&amp;lt;name&amp;gt;.+)_\d+"
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 03 Apr 2019 15:03:45 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Field-extraction-from-source-field/m-p/389788#M113569</guid>
      <dc:creator>vnravikumar</dc:creator>
      <dc:date>2019-04-03T15:03:45Z</dc:date>
    </item>
    <item>
      <title>Re: Field extraction from source field</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Field-extraction-from-source-field/m-p/389789#M113570</link>
      <description>&lt;P&gt;If you only want the filename, I think @FrankVI or @vnravikumar would be a good approach.  If you want it all parsed out:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt; | rex field=source "(?&amp;lt;logdir&amp;gt;\/[\W\w]+\/[\W\w]+\/)(?&amp;lt;date&amp;gt;[^\/]+)\/file_(?&amp;lt;filename&amp;gt;[^\_]+)\_(?&amp;lt;processid&amp;gt;[^\_]+)\_(?&amp;lt;extension&amp;gt;.+)"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Here is what I used to test it:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| makeresults 
 | eval source = "/default/folder/20190403/file_PARADOX_7747_txt" 
 | rex field=source "(?&amp;lt;logdir&amp;gt;\/[\W\w]+\/[\W\w]+\/)(?&amp;lt;date&amp;gt;[^\/]+)\/file_(?&amp;lt;filename&amp;gt;[^\_]+)\_(?&amp;lt;processid&amp;gt;[^\_]+)\_(?&amp;lt;extension&amp;gt;.+)"
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 03 Apr 2019 15:10:07 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Field-extraction-from-source-field/m-p/389789#M113570</guid>
      <dc:creator>ragedsparrow</dc:creator>
      <dc:date>2019-04-03T15:10:07Z</dc:date>
    </item>
    <item>
      <title>Re: Field extraction from source field</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Field-extraction-from-source-field/m-p/389790#M113571</link>
      <description>&lt;P&gt;Thanks @FrankVI , &lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/156785"&gt;@vnravikumar&lt;/a&gt; &amp;amp; &lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/102823"&gt;@ragedsparrow&lt;/a&gt; for all your help .&lt;/P&gt;

&lt;P&gt;Unfortunately my source pattern can contain multiple words in the file name  but filename is always suffixed by process id like below :&lt;/P&gt;

&lt;P&gt;source=/default/folder/20190403/file_PARADOX_7747_txt&lt;BR /&gt;
source=/default/folder/20190402/file_AMR_CA_1234_txt&lt;BR /&gt;
source=/default/folder/20190402/file_EMEA_IRE_DUB_8964_txt&lt;/P&gt;

&lt;P&gt;If there is a way to grab the file name between "file_" and a numeric digit ([0-9]) , it ll help .&lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2020 23:56:30 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Field-extraction-from-source-field/m-p/389790#M113571</guid>
      <dc:creator>ppatkar</dc:creator>
      <dc:date>2020-09-29T23:56:30Z</dc:date>
    </item>
    <item>
      <title>Re: Field extraction from source field</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Field-extraction-from-source-field/m-p/389791#M113572</link>
      <description>&lt;P&gt;I think this would work:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| rex field=source "(?&amp;lt;logdir&amp;gt;\/[\W\w]+\/[\W\w]+\/)(?&amp;lt;date&amp;gt;[^\/]+)\/file_(?&amp;lt;filename&amp;gt;[^\d]+)\_(?&amp;lt;processid&amp;gt;\d+)\_(?&amp;lt;extension&amp;gt;.+)"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;I tested it here:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| makeresults 
  | eval source="/default/folder/20190402/file_EMEA_IRE_DUB_8964_txt"
  | rex field=source "(?&amp;lt;logdir&amp;gt;\/[\W\w]+\/[\W\w]+\/)(?&amp;lt;date&amp;gt;[^\/]+)\/file_(?&amp;lt;filename&amp;gt;[^\d]+)\_(?&amp;lt;processid&amp;gt;\d+)\_(?&amp;lt;extension&amp;gt;.+)"
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 03 Apr 2019 16:14:32 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Field-extraction-from-source-field/m-p/389791#M113572</guid>
      <dc:creator>ragedsparrow</dc:creator>
      <dc:date>2019-04-03T16:14:32Z</dc:date>
    </item>
    <item>
      <title>Re: Field extraction from source field</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Field-extraction-from-source-field/m-p/389792#M113573</link>
      <description>&lt;P&gt;Hi&lt;/P&gt;

&lt;P&gt;Try this&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| makeresults 
 | eval source = "source=/default/folder/20190402/file_EMEA_IRE_DUB_8964_txt" 
 | rex field=source "file\_(?P&amp;lt;name&amp;gt;.+)_\d+"
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 03 Apr 2019 16:28:40 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Field-extraction-from-source-field/m-p/389792#M113573</guid>
      <dc:creator>vnravikumar</dc:creator>
      <dc:date>2019-04-03T16:28:40Z</dc:date>
    </item>
    <item>
      <title>Re: Field extraction from source field</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Field-extraction-from-source-field/m-p/389793#M113574</link>
      <description>&lt;P&gt;Works like a charm ! Thank you&lt;/P&gt;</description>
      <pubDate>Wed, 03 Apr 2019 17:33:24 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Field-extraction-from-source-field/m-p/389793#M113574</guid>
      <dc:creator>ppatkar</dc:creator>
      <dc:date>2019-04-03T17:33:24Z</dc:date>
    </item>
  </channel>
</rss>

