<?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 get count of a field per event? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-to-get-count-of-a-field-per-event/m-p/65892#M16345</link>
    <description>&lt;P&gt;Use &lt;CODE&gt;eval&lt;/CODE&gt;'s &lt;CODE&gt;mvcount&lt;/CODE&gt;:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;sourcetype=x | transaction startswith="Job start" endswith="Job complete" | eval start = _time | eval end = _time + duration | eval taskcount = mvcount(task) | table start, end, duration, taskcount
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;&lt;A href="http://docs.splunk.com/Documentation/Splunk/latest/SearchReference/CommonEvalFunctions"&gt;http://docs.splunk.com/Documentation/Splunk/latest/SearchReference/CommonEvalFunctions&lt;/A&gt;&lt;/P&gt;</description>
    <pubDate>Thu, 20 Sep 2012 10:25:53 GMT</pubDate>
    <dc:creator>Ayn</dc:creator>
    <dc:date>2012-09-20T10:25:53Z</dc:date>
    <item>
      <title>How to get count of a field per event?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-get-count-of-a-field-per-event/m-p/65891#M16344</link>
      <description>&lt;P&gt;I am using a transaction to get the start/end/duration of jobs. This gives me back about 200 events. Something like:&lt;/P&gt;

&lt;P&gt;&lt;CODE&gt;sourcetype=x | transaction startswith="Job start" endswith="Job complete" | eval start = _time | eval end = _time + duration | table start, end, duration&lt;/CODE&gt;&lt;/P&gt;

&lt;P&gt;I would like to extract the number of "tasks" that are done in in this job I use the "rex" command to get a the field:&lt;/P&gt;

&lt;P&gt;&lt;CODE&gt;rex field=_raw ".*(?&amp;lt;task&amp;gt;Task started).*" | stats count(task)&lt;/CODE&gt;&lt;/P&gt;

&lt;P&gt;unfortunatly the stats command groups all the events which I dont want. I really want something like:&lt;/P&gt;

&lt;P&gt;&lt;CODE&gt;sourcetype=x | transaction startswith="Job start" endswith="Job complete" | rex field=_raw ".*(?&amp;lt;task&amp;gt;Task started).*" | eval start = _time | eval end = _time + duration | table start, end, duration, count(task)&lt;/CODE&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 20 Sep 2012 10:08:06 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-get-count-of-a-field-per-event/m-p/65891#M16344</guid>
      <dc:creator>jameshgibson</dc:creator>
      <dc:date>2012-09-20T10:08:06Z</dc:date>
    </item>
    <item>
      <title>Re: How to get count of a field per event?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-get-count-of-a-field-per-event/m-p/65892#M16345</link>
      <description>&lt;P&gt;Use &lt;CODE&gt;eval&lt;/CODE&gt;'s &lt;CODE&gt;mvcount&lt;/CODE&gt;:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;sourcetype=x | transaction startswith="Job start" endswith="Job complete" | eval start = _time | eval end = _time + duration | eval taskcount = mvcount(task) | table start, end, duration, taskcount
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;&lt;A href="http://docs.splunk.com/Documentation/Splunk/latest/SearchReference/CommonEvalFunctions"&gt;http://docs.splunk.com/Documentation/Splunk/latest/SearchReference/CommonEvalFunctions&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 20 Sep 2012 10:25:53 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-get-count-of-a-field-per-event/m-p/65892#M16345</guid>
      <dc:creator>Ayn</dc:creator>
      <dc:date>2012-09-20T10:25:53Z</dc:date>
    </item>
    <item>
      <title>Re: How to get count of a field per event?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-get-count-of-a-field-per-event/m-p/65893#M16346</link>
      <description>&lt;P&gt;doesn't do what I need, it just returns 1 or 0 depending if there are any tasks in the transaction&lt;/P&gt;</description>
      <pubDate>Thu, 20 Sep 2012 10:52:53 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-get-count-of-a-field-per-event/m-p/65893#M16346</guid>
      <dc:creator>jameshgibson</dc:creator>
      <dc:date>2012-09-20T10:52:53Z</dc:date>
    </item>
    <item>
      <title>Re: How to get count of a field per event?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-get-count-of-a-field-per-event/m-p/65894#M16347</link>
      <description>&lt;P&gt;So you mean it's a distinct count? Then make a different field extraction through rex;&lt;/P&gt;

&lt;P&gt;&lt;CODE&gt;... | rex "(?&lt;UNIQUE_TASK_ID&gt;.{20}).*Task started" | ... &lt;/UNIQUE_TASK_ID&gt;&lt;/CODE&gt;&lt;/P&gt;

&lt;P&gt;In this case, grab the first 20 characters of your events as a unique task id (assuming there is a timestamp there - YMMV). This should do fine, if you don't really need to look a the actual values.&lt;/P&gt;

&lt;P&gt;/kristian&lt;/P&gt;</description>
      <pubDate>Thu, 20 Sep 2012 11:48:28 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-get-count-of-a-field-per-event/m-p/65894#M16347</guid>
      <dc:creator>kristian_kolb</dc:creator>
      <dc:date>2012-09-20T11:48:28Z</dc:date>
    </item>
    <item>
      <title>Re: How to get count of a field per event?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-get-count-of-a-field-per-event/m-p/65895#M16348</link>
      <description>&lt;P&gt;I just want a field count within each event. I dont care if the tasks are repeated or not.&lt;/P&gt;</description>
      <pubDate>Thu, 20 Sep 2012 13:54:02 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-get-count-of-a-field-per-event/m-p/65895#M16348</guid>
      <dc:creator>jameshgibson</dc:creator>
      <dc:date>2012-09-20T13:54:02Z</dc:date>
    </item>
  </channel>
</rss>

