<?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: Count values in different fields in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Count-values-in-different-fields/m-p/319111#M162582</link>
    <description>&lt;P&gt;Are each of these on new lines/events?&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=yourIndex
| rex field=_raw "car\.(?&amp;lt;manufacturer&amp;gt;[a-zA-Z]+) = (?&amp;lt;model&amp;gt;[a-zA-Z0-9]+)"
| stats count by manufacturer
&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Mon, 05 Mar 2018 15:50:07 GMT</pubDate>
    <dc:creator>livehybrid</dc:creator>
    <dc:date>2018-03-05T15:50:07Z</dc:date>
    <item>
      <title>Count values in different fields</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Count-values-in-different-fields/m-p/319109#M162580</link>
      <description>&lt;P&gt;Hello, &lt;/P&gt;

&lt;P&gt;I'm having an issue regarding some fields. I have several fields which start with the same name but end different. Let me explain it with an example: &lt;/P&gt;

&lt;P&gt;&lt;EM&gt;car.chevrollette = Camaro&lt;BR /&gt;
car.nissan = gtr&lt;BR /&gt;
car.bmw = 320d&lt;BR /&gt;
car.mercedes = 220CDI&lt;BR /&gt;
car.bmw = 118d&lt;BR /&gt;
car.mercedes = ClassG&lt;BR /&gt;
car.fiat = Croma&lt;BR /&gt;
car.nissan = micra&lt;BR /&gt;
car.bmw = 118d&lt;/EM&gt;&lt;BR /&gt;
[and so on...]&lt;/P&gt;

&lt;P&gt;I would like to count the number of cars regarding one brand, for example... Mercedes = 2, Nissan=2, BMW=2, Fiat=1...&lt;BR /&gt;
I don't know how to count based on the field instead of the value to create a table or a chart regarding the ocurrences.  I would also like to count the number o ocurrences based on the value, for example: 118d=2, ClassG=1, Chevrollete=1, gtr=1... &lt;/P&gt;

&lt;P&gt;¿Is there anyway to do this? &lt;/P&gt;

&lt;P&gt;Any clue will be welcome! &lt;BR /&gt;
Thank you very much in advance! &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt; &lt;/P&gt;</description>
      <pubDate>Mon, 05 Mar 2018 14:53:38 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Count-values-in-different-fields/m-p/319109#M162580</guid>
      <dc:creator>rodkinal</dc:creator>
      <dc:date>2018-03-05T14:53:38Z</dc:date>
    </item>
    <item>
      <title>Re: Count values in different fields</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Count-values-in-different-fields/m-p/319110#M162581</link>
      <description>&lt;P&gt;@rodkinal, is this how your raw data looks like or is this after field extraction? Are the field names single value or multiple value?&lt;/P&gt;

&lt;P&gt;Following is a run anywhere search based on the sample data provided (pipes &lt;CODE&gt;|&lt;/CODE&gt; from &lt;CODE&gt;makeresults&lt;/CODE&gt;  till &lt;CODE&gt;extract&lt;/CODE&gt; generate the sample data: &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| makeresults
| eval data="car.chevrollette=Camaro;car.nissan=gtr;car.bmw=320d;car.mercedes=220CDI;car.bmw=118d;car.mercedes=ClassG;car.fiat=Croma;car.nissan=micra;car.bmw=118d"
| makemv data delim=";" 
| mvexpand data
| rename data as _raw
| extract kvdelim="="
| stats count(car_*) as *
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 05 Mar 2018 15:49:50 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Count-values-in-different-fields/m-p/319110#M162581</guid>
      <dc:creator>niketn</dc:creator>
      <dc:date>2018-03-05T15:49:50Z</dc:date>
    </item>
    <item>
      <title>Re: Count values in different fields</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Count-values-in-different-fields/m-p/319111#M162582</link>
      <description>&lt;P&gt;Are each of these on new lines/events?&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=yourIndex
| rex field=_raw "car\.(?&amp;lt;manufacturer&amp;gt;[a-zA-Z]+) = (?&amp;lt;model&amp;gt;[a-zA-Z0-9]+)"
| stats count by manufacturer
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 05 Mar 2018 15:50:07 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Count-values-in-different-fields/m-p/319111#M162582</guid>
      <dc:creator>livehybrid</dc:creator>
      <dc:date>2018-03-05T15:50:07Z</dc:date>
    </item>
    <item>
      <title>Re: Count values in different fields</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Count-values-in-different-fields/m-p/319112#M162583</link>
      <description>&lt;P&gt;Helo niketnilay, &lt;/P&gt;

&lt;P&gt;Thank you very much for your quick response. The issue here is that we don't know all the possibilties so we can't build a data string. Anyway, thank you very much for your help. It's very appreciated &lt;span class="lia-unicode-emoji" title=":grinning_face_with_smiling_eyes:"&gt;😄&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 05 Mar 2018 16:38:46 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Count-values-in-different-fields/m-p/319112#M162583</guid>
      <dc:creator>rodkinal</dc:creator>
      <dc:date>2018-03-05T16:38:46Z</dc:date>
    </item>
    <item>
      <title>Re: Count values in different fields</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Count-values-in-different-fields/m-p/319113#M162584</link>
      <description>&lt;P&gt;Hello livehybrid. I have already tried to look into the raw json, but the issue here is that the json file contains several "car.manufactuer=model" entries so, using  this way, we only can list the first entry. I really appreciate you answer! &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt; Kind regards!&lt;/P&gt;</description>
      <pubDate>Mon, 05 Mar 2018 16:41:17 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Count-values-in-different-fields/m-p/319113#M162584</guid>
      <dc:creator>rodkinal</dc:creator>
      <dc:date>2018-03-05T16:41:17Z</dc:date>
    </item>
    <item>
      <title>Re: Count values in different fields</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Count-values-in-different-fields/m-p/319114#M162585</link>
      <description>&lt;P&gt;@rodkinal if you can provide the sample of raw data that you have we can create a query that would work for all combination. Above one is just run anywhere example based on data you have provided.&lt;/P&gt;

&lt;P&gt;Based on the details provided if you already have field names as &lt;CODE&gt;car.nissan&lt;/CODE&gt;, &lt;CODE&gt;car.bmw&lt;/CODE&gt; with corresponding stats, all you need is to plug in the final stats command to your current search returning the fields i.e.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;&amp;lt;YourBaseSearch&amp;gt;
| stats count(car.*) as *
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;If this does not work then maybe the data/extracted field is not of the form you have mentioned (multivalued fields need to be handled differently then single valued field etc). So, for us to assist you would need to provide some mock sample data as you are getting in your raw logs.&lt;/P&gt;</description>
      <pubDate>Mon, 05 Mar 2018 16:46:49 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Count-values-in-different-fields/m-p/319114#M162585</guid>
      <dc:creator>niketn</dc:creator>
      <dc:date>2018-03-05T16:46:49Z</dc:date>
    </item>
  </channel>
</rss>

