<?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 write a search to get an accurate count of fields with the same name in a single event? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-to-write-a-search-to-get-an-accurate-count-of-fields-with/m-p/224818#M66250</link>
    <description>&lt;P&gt;Try this&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;.... |  rex max_match=0 "GROUP=\"(?&amp;lt;group&amp;gt;[^\"]+)" | mvexpand group | stats count by group
&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Wed, 22 Jun 2016 12:10:12 GMT</pubDate>
    <dc:creator>sundareshr</dc:creator>
    <dc:date>2016-06-22T12:10:12Z</dc:date>
    <item>
      <title>How to write a search to get an accurate count of fields with the same name in a single event?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-write-a-search-to-get-an-accurate-count-of-fields-with/m-p/224817#M66249</link>
      <description>&lt;P&gt;Hello Splunkers,&lt;/P&gt;

&lt;P&gt;Here is my sample event:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;ID=000, GROUP="A", GROUP="B", TYPE="NA"
ID=001, GROUP="A", TYPE="NB"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;The problem is when I use the search command:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;    ...|stats count by GROUP
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;I will get this result in Splunk:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;GROUP          count
A              2
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;While what I really want to get is:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;GROUP          count
A              2
B              1
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;I think the problem is that the field &lt;STRONG&gt;GROUP&lt;/STRONG&gt; can have multiple values per event, and Splunk just takes the first as its value. Since I can't change the source data, what can I do with this situation?&lt;/P&gt;

&lt;P&gt;Thank you very much for your attention.&lt;BR /&gt;
Daiyu&lt;/P&gt;</description>
      <pubDate>Wed, 22 Jun 2016 11:29:45 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-write-a-search-to-get-an-accurate-count-of-fields-with/m-p/224817#M66249</guid>
      <dc:creator>Lindaiyu</dc:creator>
      <dc:date>2016-06-22T11:29:45Z</dc:date>
    </item>
    <item>
      <title>Re: How to write a search to get an accurate count of fields with the same name in a single event?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-write-a-search-to-get-an-accurate-count-of-fields-with/m-p/224818#M66250</link>
      <description>&lt;P&gt;Try this&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;.... |  rex max_match=0 "GROUP=\"(?&amp;lt;group&amp;gt;[^\"]+)" | mvexpand group | stats count by group
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 22 Jun 2016 12:10:12 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-write-a-search-to-get-an-accurate-count-of-fields-with/m-p/224818#M66250</guid>
      <dc:creator>sundareshr</dc:creator>
      <dc:date>2016-06-22T12:10:12Z</dc:date>
    </item>
    <item>
      <title>Re: How to write a search to get an accurate count of fields with the same name in a single event?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-write-a-search-to-get-an-accurate-count-of-fields-with/m-p/224819#M66251</link>
      <description>&lt;P&gt;You can try extracting GROUP as a multivalued field with the rex command. This may work: &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt; &amp;lt;your search&amp;gt; | rex max_match=0 "GROUP=\"(?&amp;lt;group&amp;gt;[^\"])" | mvexpand group | stats count by group
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;The rex command (&lt;A href="http://docs.splunk.com/Documentation/Splunk/6.4.1/SearchReference/Rex"&gt;http://docs.splunk.com/Documentation/Splunk/6.4.1/SearchReference/Rex&lt;/A&gt;) will extract a new field. Setting max_match to 0 means rex will not stop at the first match, and it will combine the results in a multivalued field.  In your example, your events will now look like this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt; ID       TYPE    group
-------------------------------
 000       NA       A
                    B
--------------------------------
 001       NB       A
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;mvexpand (&lt;A href="http://docs.splunk.com/Documentation/Splunk/6.4.1/SearchReference/Mvexpand"&gt;http://docs.splunk.com/Documentation/Splunk/6.4.1/SearchReference/Mvexpand&lt;/A&gt;) will split the multivalue fields, so now you will have three events, like so: &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt; ID       TYPE    group
-------------------------------
 000       NA       A
-------------------------------
 000       NA       B
--------------------------------
 001       NB       A
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Now your stats commands will work the way you want.  For regex help try &lt;A href="https://regex101.com/"&gt;https://regex101.com/&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 22 Jun 2016 12:21:54 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-write-a-search-to-get-an-accurate-count-of-fields-with/m-p/224819#M66251</guid>
      <dc:creator>jplumsdaine22</dc:creator>
      <dc:date>2016-06-22T12:21:54Z</dc:date>
    </item>
    <item>
      <title>Re: How to write a search to get an accurate count of fields with the same name in a single event?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-write-a-search-to-get-an-accurate-count-of-fields-with/m-p/224820#M66252</link>
      <description>&lt;P&gt;If using &lt;CODE&gt;rex&lt;/CODE&gt; then add &lt;CODE&gt;max_match=0&lt;/CODE&gt;; if using &lt;CODE&gt;props.conf&lt;/CODE&gt;, then add &lt;CODE&gt;MV_ADD=1&lt;/CODE&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 22 Jun 2016 12:23:54 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-write-a-search-to-get-an-accurate-count-of-fields-with/m-p/224820#M66252</guid>
      <dc:creator>woodcock</dc:creator>
      <dc:date>2016-06-22T12:23:54Z</dc:date>
    </item>
    <item>
      <title>Re: How to write a search to get an accurate count of fields with the same name in a single event?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-write-a-search-to-get-an-accurate-count-of-fields-with/m-p/224821#M66253</link>
      <description>&lt;P&gt;Give this a try as well (in-line with search)&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;your base search | table _raw | extract kvdelim="=" mv_add=t | stats count by group
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 22 Jun 2016 16:08:20 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-write-a-search-to-get-an-accurate-count-of-fields-with/m-p/224821#M66253</guid>
      <dc:creator>somesoni2</dc:creator>
      <dc:date>2016-06-22T16:08:20Z</dc:date>
    </item>
    <item>
      <title>Re: How to write a search to get an accurate count of fields with the same name in a single event?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-write-a-search-to-get-an-accurate-count-of-fields-with/m-p/224822#M66254</link>
      <description>&lt;P&gt;it works and thank you very much for you help!&lt;/P&gt;</description>
      <pubDate>Fri, 24 Jun 2016 13:50:59 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-write-a-search-to-get-an-accurate-count-of-fields-with/m-p/224822#M66254</guid>
      <dc:creator>Lindaiyu</dc:creator>
      <dc:date>2016-06-24T13:50:59Z</dc:date>
    </item>
    <item>
      <title>Re: How to write a search to get an accurate count of fields with the same name in a single event?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-write-a-search-to-get-an-accurate-count-of-fields-with/m-p/224823#M66255</link>
      <description>&lt;P&gt;thank you very much for you help! I really learn something!&lt;/P&gt;</description>
      <pubDate>Fri, 24 Jun 2016 13:51:37 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-write-a-search-to-get-an-accurate-count-of-fields-with/m-p/224823#M66255</guid>
      <dc:creator>Lindaiyu</dc:creator>
      <dc:date>2016-06-24T13:51:37Z</dc:date>
    </item>
    <item>
      <title>Re: How to write a search to get an accurate count of fields with the same name in a single event?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-write-a-search-to-get-an-accurate-count-of-fields-with/m-p/224824#M66256</link>
      <description>&lt;P&gt;thank you very much for you help! &lt;/P&gt;</description>
      <pubDate>Fri, 24 Jun 2016 13:51:47 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-write-a-search-to-get-an-accurate-count-of-fields-with/m-p/224824#M66256</guid>
      <dc:creator>Lindaiyu</dc:creator>
      <dc:date>2016-06-24T13:51:47Z</dc:date>
    </item>
    <item>
      <title>Re: How to write a search to get an accurate count of fields with the same name in a single event?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-write-a-search-to-get-an-accurate-count-of-fields-with/m-p/224825#M66257</link>
      <description>&lt;P&gt;Thank you very much!&lt;/P&gt;</description>
      <pubDate>Fri, 24 Jun 2016 13:52:03 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-write-a-search-to-get-an-accurate-count-of-fields-with/m-p/224825#M66257</guid>
      <dc:creator>Lindaiyu</dc:creator>
      <dc:date>2016-06-24T13:52:03Z</dc:date>
    </item>
  </channel>
</rss>

