<?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: Get the length of a file name before the extension in Dashboards &amp; Visualizations</title>
    <link>https://community.splunk.com/t5/Dashboards-Visualizations/Get-the-length-of-a-file-name-before-the-extension/m-p/184913#M11415</link>
    <description>&lt;P&gt;My regex works like this, from right to left:&lt;/P&gt;

&lt;UL&gt;
&lt;LI&gt;Anchor to the end of the field&lt;/LI&gt;
&lt;LI&gt;Match one or more characters that are not a literal dot&lt;/LI&gt;
&lt;LI&gt;Match one literal dot&lt;/LI&gt;
&lt;/UL&gt;

&lt;P&gt;Then that match is removed from the string by the replace, so the length only counts the filename without the extension. Some examples, with parentheses denoting the matched and removed part:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;file(.name) --&amp;gt; length is 4
some.other.file(.name) --&amp;gt; length is 14
(.hidden) --&amp;gt; length is 0
&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Thu, 13 Mar 2014 12:49:42 GMT</pubDate>
    <dc:creator>martin_mueller</dc:creator>
    <dc:date>2014-03-13T12:49:42Z</dc:date>
    <item>
      <title>Get the length of a file name before the extension</title>
      <link>https://community.splunk.com/t5/Dashboards-Visualizations/Get-the-length-of-a-file-name-before-the-extension/m-p/184909#M11411</link>
      <description>&lt;P&gt;I searched this one quite a bit because the solution seemed like it would be really easy.&lt;/P&gt;

&lt;P&gt;Given the filename field has only a name.extension, I want to count the length of the name, which is 4 in this case.&lt;/P&gt;

&lt;P&gt;In Excel, I would just do =len(left(A2,Find(“.“,A2))), I believe.  Seems really easy.&lt;/P&gt;

&lt;P&gt;Examples:&lt;BR /&gt;
a.txt 1&lt;BR /&gt;
bee.bat 3&lt;BR /&gt;
ce.command 2&lt;/P&gt;</description>
      <pubDate>Wed, 12 Mar 2014 20:13:32 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Dashboards-Visualizations/Get-the-length-of-a-file-name-before-the-extension/m-p/184909#M11411</guid>
      <dc:creator>landen99</dc:creator>
      <dc:date>2014-03-12T20:13:32Z</dc:date>
    </item>
    <item>
      <title>Re: Get the length of a file name before the extension</title>
      <link>https://community.splunk.com/t5/Dashboards-Visualizations/Get-the-length-of-a-file-name-before-the-extension/m-p/184910#M11412</link>
      <description>&lt;P&gt;Take a look at this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| stats count | eval file="a.txt bee.bat ce.command" | makemv file | mvexpand file | eval count = length(replace(file, "\.[^.]+$", ""))
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;That creates a field &lt;CODE&gt;file&lt;/CODE&gt; with your examples, and computes a field &lt;CODE&gt;count&lt;/CODE&gt; that matches your results - that's the eval at the end, same strategy as your Excel computation.&lt;/P&gt;</description>
      <pubDate>Wed, 12 Mar 2014 20:41:16 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Dashboards-Visualizations/Get-the-length-of-a-file-name-before-the-extension/m-p/184910#M11412</guid>
      <dc:creator>martin_mueller</dc:creator>
      <dc:date>2014-03-12T20:41:16Z</dc:date>
    </item>
    <item>
      <title>Re: Get the length of a file name before the extension</title>
      <link>https://community.splunk.com/t5/Dashboards-Visualizations/Get-the-length-of-a-file-name-before-the-extension/m-p/184911#M11413</link>
      <description>&lt;P&gt;Your answer helped me to build the search below for good results:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| eval file_length=length(replace(filename, "\.[^.]+$", ""))
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;UL&gt;
&lt;LI&gt;Does your search produce the same results or something different than the search above?&lt;/LI&gt;
&lt;LI&gt;Also, why do you invoke stats count and count in eval?&lt;/LI&gt;
&lt;/UL&gt;

&lt;P&gt;Here are a few of the regex suggestions I have read:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;([^\.]*)
/^(.+)(\.[^ .]+)?$/
\.[^.]*$
(.+?)(\.[^.]*$|$)
(.+?)\.[^\.]+$
(.+?)(\.[^\.]+$|$)
^(.*)\..*$
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Learning regex atm.&lt;BR /&gt;
-What is the difference between your regex and &lt;CODE&gt;^(.*)\..*$&lt;/CODE&gt;?  They seem to do the same thing as well.&lt;/P&gt;</description>
      <pubDate>Thu, 13 Mar 2014 12:41:27 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Dashboards-Visualizations/Get-the-length-of-a-file-name-before-the-extension/m-p/184911#M11413</guid>
      <dc:creator>landen99</dc:creator>
      <dc:date>2014-03-13T12:41:27Z</dc:date>
    </item>
    <item>
      <title>Re: Get the length of a file name before the extension</title>
      <link>https://community.splunk.com/t5/Dashboards-Visualizations/Get-the-length-of-a-file-name-before-the-extension/m-p/184912#M11414</link>
      <description>&lt;P&gt;I start the search with &lt;CODE&gt;| stats count&lt;/CODE&gt; to get an empty event to work with, no need for data from any index. The first &lt;CODE&gt;eval | makemv | mvexpand&lt;/CODE&gt; builds simulation data, the &lt;CODE&gt;eval&lt;/CODE&gt; at the end is the part you need for your search... it might look something like this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=foo sourcetype=bar filename=* | eval filename_length = length(replace(filename, "\.[^.]+$", ""))
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Your regexes are hard to read, Splunk Answers treats backslashes, asterisks, and underscores within regular text as special characters. Prepend four spaces to your regexes to avoid that.&lt;/P&gt;</description>
      <pubDate>Thu, 13 Mar 2014 12:47:16 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Dashboards-Visualizations/Get-the-length-of-a-file-name-before-the-extension/m-p/184912#M11414</guid>
      <dc:creator>martin_mueller</dc:creator>
      <dc:date>2014-03-13T12:47:16Z</dc:date>
    </item>
    <item>
      <title>Re: Get the length of a file name before the extension</title>
      <link>https://community.splunk.com/t5/Dashboards-Visualizations/Get-the-length-of-a-file-name-before-the-extension/m-p/184913#M11415</link>
      <description>&lt;P&gt;My regex works like this, from right to left:&lt;/P&gt;

&lt;UL&gt;
&lt;LI&gt;Anchor to the end of the field&lt;/LI&gt;
&lt;LI&gt;Match one or more characters that are not a literal dot&lt;/LI&gt;
&lt;LI&gt;Match one literal dot&lt;/LI&gt;
&lt;/UL&gt;

&lt;P&gt;Then that match is removed from the string by the replace, so the length only counts the filename without the extension. Some examples, with parentheses denoting the matched and removed part:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;file(.name) --&amp;gt; length is 4
some.other.file(.name) --&amp;gt; length is 14
(.hidden) --&amp;gt; length is 0
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 13 Mar 2014 12:49:42 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Dashboards-Visualizations/Get-the-length-of-a-file-name-before-the-extension/m-p/184913#M11415</guid>
      <dc:creator>martin_mueller</dc:creator>
      <dc:date>2014-03-13T12:49:42Z</dc:date>
    </item>
    <item>
      <title>Re: Get the length of a file name before the extension</title>
      <link>https://community.splunk.com/t5/Dashboards-Visualizations/Get-the-length-of-a-file-name-before-the-extension/m-p/184914#M11416</link>
      <description>&lt;P&gt;The actual excel code would really be: =LEN(LEFT(A1,FIND(".",A1,1)-1))&lt;/P&gt;</description>
      <pubDate>Thu, 13 Mar 2014 12:49:49 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Dashboards-Visualizations/Get-the-length-of-a-file-name-before-the-extension/m-p/184914#M11416</guid>
      <dc:creator>landen99</dc:creator>
      <dc:date>2014-03-13T12:49:49Z</dc:date>
    </item>
    <item>
      <title>Re: Get the length of a file name before the extension</title>
      <link>https://community.splunk.com/t5/Dashboards-Visualizations/Get-the-length-of-a-file-name-before-the-extension/m-p/184915#M11417</link>
      <description>&lt;P&gt;I added 4 spaces before each regex expression.  Is that what you were after?&lt;/P&gt;

&lt;P&gt;I wish this site was easier to post to.  I have a lot of difficulty with the captcha working and there are no tools for inserting html codes like spoiler, code, image, etc to the post.&lt;/P&gt;</description>
      <pubDate>Thu, 13 Mar 2014 13:00:59 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Dashboards-Visualizations/Get-the-length-of-a-file-name-before-the-extension/m-p/184915#M11417</guid>
      <dc:creator>landen99</dc:creator>
      <dc:date>2014-03-13T13:00:59Z</dc:date>
    </item>
    <item>
      <title>Re: Get the length of a file name before the extension</title>
      <link>https://community.splunk.com/t5/Dashboards-Visualizations/Get-the-length-of-a-file-name-before-the-extension/m-p/184916#M11418</link>
      <description>&lt;P&gt;I have edited the comment, the four-spaces-block needs an empty line before it to work properly. Now asterisks and all that are rendered correctly. For posting code blocks inline surround it by backticks (`).&lt;/P&gt;</description>
      <pubDate>Thu, 13 Mar 2014 13:04:30 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Dashboards-Visualizations/Get-the-length-of-a-file-name-before-the-extension/m-p/184916#M11418</guid>
      <dc:creator>martin_mueller</dc:creator>
      <dc:date>2014-03-13T13:04:30Z</dc:date>
    </item>
    <item>
      <title>Re: Get the length of a file name before the extension</title>
      <link>https://community.splunk.com/t5/Dashboards-Visualizations/Get-the-length-of-a-file-name-before-the-extension/m-p/184917#M11419</link>
      <description>&lt;P&gt;As for your question "-What is the difference between your regex and &lt;CODE&gt;^(.*)\..*$&lt;/CODE&gt;?  They seem to do the same thing as well.", yours looks for the first literal dot while mine looks for the last literal dot. An example:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;some.other.file(.name) --&amp;gt; my regex will match only the .name, length is 14
some(.other.file.name) --&amp;gt; your regex will match the entire string, and when replaced with $1 the remaining length will be 4
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 13 Mar 2014 13:07:07 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Dashboards-Visualizations/Get-the-length-of-a-file-name-before-the-extension/m-p/184917#M11419</guid>
      <dc:creator>martin_mueller</dc:creator>
      <dc:date>2014-03-13T13:07:07Z</dc:date>
    </item>
    <item>
      <title>Re: Get the length of a file name before the extension</title>
      <link>https://community.splunk.com/t5/Dashboards-Visualizations/Get-the-length-of-a-file-name-before-the-extension/m-p/184918#M11420</link>
      <description>&lt;P&gt;Perfect.  Thank you very much for your insight and guidance here.&lt;/P&gt;</description>
      <pubDate>Thu, 13 Mar 2014 13:23:52 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Dashboards-Visualizations/Get-the-length-of-a-file-name-before-the-extension/m-p/184918#M11420</guid>
      <dc:creator>landen99</dc:creator>
      <dc:date>2014-03-13T13:23:52Z</dc:date>
    </item>
  </channel>
</rss>

