<?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 Remove last values of a field result in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Remove-last-values-of-a-field-result/m-p/353905#M170158</link>
    <description>&lt;P&gt;following  are the output of a filed&lt;/P&gt;

&lt;P&gt;file=a.csv&lt;BR /&gt;
file=a1.csv&lt;BR /&gt;
file=a2.csv&lt;BR /&gt;
file=b.csv&lt;BR /&gt;
file=b1.csv&lt;/P&gt;

&lt;P&gt;What i required is while executing |stats count by file i need following result&lt;BR /&gt;
a=3 and b=2&lt;BR /&gt;
is there any way to get this result&lt;/P&gt;</description>
    <pubDate>Fri, 20 Apr 2018 17:15:59 GMT</pubDate>
    <dc:creator>n4niyaz</dc:creator>
    <dc:date>2018-04-20T17:15:59Z</dc:date>
    <item>
      <title>Remove last values of a field result</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Remove-last-values-of-a-field-result/m-p/353905#M170158</link>
      <description>&lt;P&gt;following  are the output of a filed&lt;/P&gt;

&lt;P&gt;file=a.csv&lt;BR /&gt;
file=a1.csv&lt;BR /&gt;
file=a2.csv&lt;BR /&gt;
file=b.csv&lt;BR /&gt;
file=b1.csv&lt;/P&gt;

&lt;P&gt;What i required is while executing |stats count by file i need following result&lt;BR /&gt;
a=3 and b=2&lt;BR /&gt;
is there any way to get this result&lt;/P&gt;</description>
      <pubDate>Fri, 20 Apr 2018 17:15:59 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Remove-last-values-of-a-field-result/m-p/353905#M170158</guid>
      <dc:creator>n4niyaz</dc:creator>
      <dc:date>2018-04-20T17:15:59Z</dc:date>
    </item>
    <item>
      <title>Re: Remove last values of a field result</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Remove-last-values-of-a-field-result/m-p/353906#M170159</link>
      <description>&lt;P&gt;You can use this to get the first character of the file name:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| eval file=substr(file,0,1)
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;So insert that directly before your call to&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| stats count by file
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;and you should get the desired result.&lt;/P&gt;</description>
      <pubDate>Fri, 20 Apr 2018 17:51:55 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Remove-last-values-of-a-field-result/m-p/353906#M170159</guid>
      <dc:creator>elliotproebstel</dc:creator>
      <dc:date>2018-04-20T17:51:55Z</dc:date>
    </item>
    <item>
      <title>Re: Remove last values of a field result</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Remove-last-values-of-a-field-result/m-p/353907#M170160</link>
      <description>&lt;P&gt;above looking good but suppose if the the field name contains date and time like below&lt;/P&gt;

&lt;P&gt;file=a_2017-09-16_12:00:00.csv&lt;BR /&gt;
file=a_2017-09-17_12:00:00.csv&lt;BR /&gt;
file=b.csv&lt;BR /&gt;
file=b1.csv&lt;BR /&gt;
file=b_2017-09-17_12:00:00.csv&lt;/P&gt;

&lt;P&gt;|stats count by file gives a=2 and b=2 and b1 =1&lt;/P&gt;

&lt;P&gt;Can i get this result using regex&lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2020 19:10:57 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Remove-last-values-of-a-field-result/m-p/353907#M170160</guid>
      <dc:creator>n4niyaz</dc:creator>
      <dc:date>2020-09-29T19:10:57Z</dc:date>
    </item>
    <item>
      <title>Re: Remove last values of a field result</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Remove-last-values-of-a-field-result/m-p/353908#M170161</link>
      <description>&lt;P&gt;Sure. If you want the category of file to be "everything that comes before either a period or an underscore", then this will work:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;|rex mode=sed field=file "s/([^_\.]+)(.*)/\1/"
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 20 Apr 2018 18:47:46 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Remove-last-values-of-a-field-result/m-p/353908#M170161</guid>
      <dc:creator>elliotproebstel</dc:creator>
      <dc:date>2018-04-20T18:47:46Z</dc:date>
    </item>
    <item>
      <title>Re: Remove last values of a field result</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Remove-last-values-of-a-field-result/m-p/353909#M170162</link>
      <description>&lt;P&gt;Thanks @elliotproebstel I used mvindex(split) command so it works fine  ie&lt;/P&gt;

&lt;P&gt;|eval test=mvindex(split(file,_201),0) so i get the result now.&lt;/P&gt;</description>
      <pubDate>Sat, 21 Apr 2018 17:52:32 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Remove-last-values-of-a-field-result/m-p/353909#M170162</guid>
      <dc:creator>n4niyaz</dc:creator>
      <dc:date>2018-04-21T17:52:32Z</dc:date>
    </item>
  </channel>
</rss>

