<?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 extract a file name up to a specific character in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-to-extract-a-file-name-up-to-a-specific-character/m-p/317476#M94965</link>
    <description>&lt;P&gt;I believe you need this regex:&lt;/P&gt;

&lt;P&gt;&lt;CODE&gt;| rex field=source "^(?&amp;lt;mything&amp;gt;[^_\.]*)(_[^\.]*)?\.log"&lt;/CODE&gt;&lt;/P&gt;

&lt;P&gt;The one @cusello posted above is close but will not extract the lines that do not contain underscores. He's also right, though, that you can't have an &lt;CODE&gt;inputlookup&lt;/CODE&gt; in the middle of your search. Perhaps you meant to append the contents of the lookup file to the existing search results, in which case you'd want &lt;CODE&gt;...| append [ | inputlookup append=T filetypes_prod.csv ] | stats count by filetype...&lt;/CODE&gt;&lt;/P&gt;</description>
    <pubDate>Wed, 18 Oct 2017 15:28:29 GMT</pubDate>
    <dc:creator>elliotproebstel</dc:creator>
    <dc:date>2017-10-18T15:28:29Z</dc:date>
    <item>
      <title>How to extract a file name up to a specific character</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-extract-a-file-name-up-to-a-specific-character/m-p/317472#M94961</link>
      <description>&lt;P&gt;I have a list of files similar to this list:&lt;/P&gt;

&lt;P&gt;FileObjMgr_01235_567.log&lt;BR /&gt;
EIM_0080123_45.log&lt;BR /&gt;
EIM_01031234_56.log&lt;BR /&gt;
EIM_01272345_67.log&lt;BR /&gt;
FINSObjMgr_56789_1234.log&lt;BR /&gt;
File3Svc.log&lt;BR /&gt;
SCFile_123456_1345.log&lt;BR /&gt;
SRFile_5794_5879.log&lt;BR /&gt;
ServerMgr_54525852_452.log&lt;BR /&gt;
SvrTaskPersist_857494_58674.log&lt;BR /&gt;
WfProcBatch_748490_5857.log&lt;BR /&gt;
WfProcMgr_2971_9928.log&lt;BR /&gt;
XMLPReporter_8751_35485.log&lt;/P&gt;

&lt;P&gt;I am trying to extract the first part of the file name up to the "&lt;EM&gt;" character. Some files do not have an "&lt;/EM&gt;" so I need the name up to .log. So far I've only been able to successfully pull names using this:&lt;/P&gt;

&lt;P&gt;index= sourcetype=:* | rex field=source ".&lt;EM&gt;/(?[A-Z]\w\w\w\w\w\w\w).&lt;/EM&gt;.log" | inputlookup append=T filetypes_prod.csv| stats count by filetype | eval Status=if(count&amp;lt;2, "Missing", "OK") | sort filetype| outputlookup filetypes_prod.csv&lt;/P&gt;

&lt;P&gt;However I am getting too many characters as below. How to I extract just to the "_" and, if that is not present to .log?&lt;/P&gt;

&lt;P&gt;EAIObjMg&lt;BR /&gt;
EIM_0080&lt;BR /&gt;
EIM_0103&lt;BR /&gt;
EIM_0127&lt;BR /&gt;
EIM_0151&lt;BR /&gt;
EIM_0171&lt;BR /&gt;
EIM_0191&lt;BR /&gt;
EIM_0223&lt;BR /&gt;
FINSObjM&lt;BR /&gt;
MASL3Svc&lt;BR /&gt;
SCBroker&lt;BR /&gt;
SRBroker&lt;BR /&gt;
ServerMg&lt;BR /&gt;
SvrTaskP&lt;BR /&gt;
WfProcBa&lt;BR /&gt;
WfProcMg&lt;BR /&gt;
XMLPRepo&lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2020 16:20:20 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-extract-a-file-name-up-to-a-specific-character/m-p/317472#M94961</guid>
      <dc:creator>sheloaha</dc:creator>
      <dc:date>2020-09-29T16:20:20Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract a file name up to a specific character</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-extract-a-file-name-up-to-a-specific-character/m-p/317473#M94962</link>
      <description>&lt;P&gt;Sorry. That should read "up to the "_" character." &lt;/P&gt;</description>
      <pubDate>Wed, 18 Oct 2017 15:00:44 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-extract-a-file-name-up-to-a-specific-character/m-p/317473#M94962</guid>
      <dc:creator>sheloaha</dc:creator>
      <dc:date>2017-10-18T15:00:44Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract a file name up to a specific character</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-extract-a-file-name-up-to-a-specific-character/m-p/317474#M94963</link>
      <description>&lt;P&gt;Hi sheloaha,&lt;BR /&gt;
If I correctly understand, do you like to extract only chars before the first "_" if present, correct?&lt;BR /&gt;
if this is your need use this regex&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| rex field=source "^(?&amp;lt;myfield&amp;gt;[^_]*)"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Viewing you search I see an error: you cannot use &lt;CODE&gt;| inputlookup&lt;/CODE&gt; in the middle of a search, only at starting point.&lt;/P&gt;

&lt;P&gt;Bye.&lt;BR /&gt;
Giuseppe&lt;/P&gt;</description>
      <pubDate>Wed, 18 Oct 2017 15:09:27 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-extract-a-file-name-up-to-a-specific-character/m-p/317474#M94963</guid>
      <dc:creator>gcusello</dc:creator>
      <dc:date>2017-10-18T15:09:27Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract a file name up to a specific character</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-extract-a-file-name-up-to-a-specific-character/m-p/317475#M94964</link>
      <description>&lt;P&gt;you can try | rex field=source "(?\w*)_ "&lt;/P&gt;</description>
      <pubDate>Wed, 18 Oct 2017 15:27:25 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-extract-a-file-name-up-to-a-specific-character/m-p/317475#M94964</guid>
      <dc:creator>kunalmao</dc:creator>
      <dc:date>2017-10-18T15:27:25Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract a file name up to a specific character</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-extract-a-file-name-up-to-a-specific-character/m-p/317476#M94965</link>
      <description>&lt;P&gt;I believe you need this regex:&lt;/P&gt;

&lt;P&gt;&lt;CODE&gt;| rex field=source "^(?&amp;lt;mything&amp;gt;[^_\.]*)(_[^\.]*)?\.log"&lt;/CODE&gt;&lt;/P&gt;

&lt;P&gt;The one @cusello posted above is close but will not extract the lines that do not contain underscores. He's also right, though, that you can't have an &lt;CODE&gt;inputlookup&lt;/CODE&gt; in the middle of your search. Perhaps you meant to append the contents of the lookup file to the existing search results, in which case you'd want &lt;CODE&gt;...| append [ | inputlookup append=T filetypes_prod.csv ] | stats count by filetype...&lt;/CODE&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 18 Oct 2017 15:28:29 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-extract-a-file-name-up-to-a-specific-character/m-p/317476#M94965</guid>
      <dc:creator>elliotproebstel</dc:creator>
      <dc:date>2017-10-18T15:28:29Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract a file name up to a specific character</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-extract-a-file-name-up-to-a-specific-character/m-p/317477#M94966</link>
      <description>&lt;P&gt;Correct suggestion:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| rex field=source "^(?&amp;lt;myfield&amp;gt;[^_\.]*)"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Bye.&lt;BR /&gt;
Giuseppe&lt;/P&gt;</description>
      <pubDate>Wed, 18 Oct 2017 15:37:24 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-extract-a-file-name-up-to-a-specific-character/m-p/317477#M94966</guid>
      <dc:creator>gcusello</dc:creator>
      <dc:date>2017-10-18T15:37:24Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract a file name up to a specific character</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-extract-a-file-name-up-to-a-specific-character/m-p/317478#M94967</link>
      <description>&lt;P&gt;This worked great! And thanks everyone for correcting my inputlookup error.&lt;/P&gt;</description>
      <pubDate>Wed, 18 Oct 2017 19:04:51 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-extract-a-file-name-up-to-a-specific-character/m-p/317478#M94967</guid>
      <dc:creator>sheloaha</dc:creator>
      <dc:date>2017-10-18T19:04:51Z</dc:date>
    </item>
  </channel>
</rss>

