<?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: stats on the presence of a field in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/stats-on-the-presence-of-a-field/m-p/24024#M4363</link>
    <description>&lt;P&gt;The best you can do given your requirement of not knowing the fields ahead of time is:&lt;/P&gt;

&lt;P&gt;&lt;CODE&gt;... | stats count(*) | transpose&lt;/CODE&gt;&lt;/P&gt;

&lt;P&gt;This will give you a count of ALL fields present in the search. &lt;/P&gt;

&lt;P&gt;Hope this helps.&lt;/P&gt;

&lt;P&gt;&lt;CODE&gt;&amp;gt; please upvote and accept answer if you find it useful - thanks!&lt;/CODE&gt;&lt;/P&gt;</description>
    <pubDate>Tue, 29 Nov 2011 20:47:05 GMT</pubDate>
    <dc:creator>_d_</dc:creator>
    <dc:date>2011-11-29T20:47:05Z</dc:date>
    <item>
      <title>stats on the presence of a field</title>
      <link>https://community.splunk.com/t5/Splunk-Search/stats-on-the-presence-of-a-field/m-p/24021#M4360</link>
      <description>&lt;P&gt;Hi,&lt;BR /&gt;
  I have a set of splunk entries where it can be one of several pattern of fields.  So for example:&lt;/P&gt;

&lt;P&gt;2011-01-01T12:00:00.000-0800 a=1 b=2&lt;BR /&gt;
2011-01-01T12:00:00.001-0800 a=1 b=2&lt;BR /&gt;
2011-01-01T12:00:00.002-0800 c=10&lt;BR /&gt;
2011-01-01T12:00:00.003-0800 c=10&lt;BR /&gt;
2011-01-01T12:00:00.004-0800 c=10&lt;BR /&gt;
2011-01-01T12:00:00.005-0800 d=99&lt;/P&gt;

&lt;P&gt;So with the above data I want to get the count of the presence of a field.  So the output of such a query would be something like this:&lt;/P&gt;

&lt;P&gt;fields  |  count&lt;BR /&gt;
a       |  2&lt;BR /&gt;
b       |  2&lt;BR /&gt;
c       |  3&lt;BR /&gt;
d       |  1&lt;/P&gt;

&lt;P&gt;Can anyone suggest a query for me to use to do this?&lt;/P&gt;</description>
      <pubDate>Tue, 29 Nov 2011 00:58:53 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/stats-on-the-presence-of-a-field/m-p/24021#M4360</guid>
      <dc:creator>Samslara</dc:creator>
      <dc:date>2011-11-29T00:58:53Z</dc:date>
    </item>
    <item>
      <title>Re: stats on the presence of a field</title>
      <link>https://community.splunk.com/t5/Splunk-Search/stats-on-the-presence-of-a-field/m-p/24022#M4361</link>
      <description>&lt;P&gt;Is it important to have the results in columns rather than rows?&lt;/P&gt;

&lt;P&gt;You could do&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;... | stats count(a),count(b),count(c),count(d)
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;which will give you a count of each field in a new column. If you want it in rows instead, as in your example, use &lt;CODE&gt;transpose&lt;/CODE&gt;:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;... | stats count(a),count(b),count(c),count(d) | transpose
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 29 Nov 2011 07:54:29 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/stats-on-the-presence-of-a-field/m-p/24022#M4361</guid>
      <dc:creator>Ayn</dc:creator>
      <dc:date>2011-11-29T07:54:29Z</dc:date>
    </item>
    <item>
      <title>Re: stats on the presence of a field</title>
      <link>https://community.splunk.com/t5/Splunk-Search/stats-on-the-presence-of-a-field/m-p/24023#M4362</link>
      <description>&lt;P&gt;This would work if I knew all the fields that would be present, but suppose I didn't know.  Is there a way to do this?&lt;/P&gt;</description>
      <pubDate>Tue, 29 Nov 2011 20:21:17 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/stats-on-the-presence-of-a-field/m-p/24023#M4362</guid>
      <dc:creator>Samslara</dc:creator>
      <dc:date>2011-11-29T20:21:17Z</dc:date>
    </item>
    <item>
      <title>Re: stats on the presence of a field</title>
      <link>https://community.splunk.com/t5/Splunk-Search/stats-on-the-presence-of-a-field/m-p/24024#M4363</link>
      <description>&lt;P&gt;The best you can do given your requirement of not knowing the fields ahead of time is:&lt;/P&gt;

&lt;P&gt;&lt;CODE&gt;... | stats count(*) | transpose&lt;/CODE&gt;&lt;/P&gt;

&lt;P&gt;This will give you a count of ALL fields present in the search. &lt;/P&gt;

&lt;P&gt;Hope this helps.&lt;/P&gt;

&lt;P&gt;&lt;CODE&gt;&amp;gt; please upvote and accept answer if you find it useful - thanks!&lt;/CODE&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 29 Nov 2011 20:47:05 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/stats-on-the-presence-of-a-field/m-p/24024#M4363</guid>
      <dc:creator>_d_</dc:creator>
      <dc:date>2011-11-29T20:47:05Z</dc:date>
    </item>
    <item>
      <title>Re: stats on the presence of a field</title>
      <link>https://community.splunk.com/t5/Splunk-Search/stats-on-the-presence-of-a-field/m-p/24025#M4364</link>
      <description>&lt;P&gt;Just use wildcards:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;... | stats count(*)
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 29 Nov 2011 21:05:26 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/stats-on-the-presence-of-a-field/m-p/24025#M4364</guid>
      <dc:creator>Ayn</dc:creator>
      <dc:date>2011-11-29T21:05:26Z</dc:date>
    </item>
    <item>
      <title>Re: stats on the presence of a field</title>
      <link>https://community.splunk.com/t5/Splunk-Search/stats-on-the-presence-of-a-field/m-p/24026#M4365</link>
      <description>&lt;P&gt;Thanks, this was very helpful.&lt;/P&gt;</description>
      <pubDate>Tue, 29 Nov 2011 21:45:15 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/stats-on-the-presence-of-a-field/m-p/24026#M4365</guid>
      <dc:creator>Samslara</dc:creator>
      <dc:date>2011-11-29T21:45:15Z</dc:date>
    </item>
    <item>
      <title>Re: stats on the presence of a field</title>
      <link>https://community.splunk.com/t5/Splunk-Search/stats-on-the-presence-of-a-field/m-p/24027#M4366</link>
      <description>&lt;P&gt;Thank you.&lt;/P&gt;</description>
      <pubDate>Tue, 29 Nov 2011 21:48:30 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/stats-on-the-presence-of-a-field/m-p/24027#M4366</guid>
      <dc:creator>Samslara</dc:creator>
      <dc:date>2011-11-29T21:48:30Z</dc:date>
    </item>
    <item>
      <title>Re: stats on the presence of a field</title>
      <link>https://community.splunk.com/t5/Splunk-Search/stats-on-the-presence-of-a-field/m-p/24028#M4367</link>
      <description>&lt;P&gt;One way I was going about it was to use rex:&lt;/P&gt;

&lt;P&gt;... | rex field=_raw "\t(?&lt;MYFIELDS&gt;[^=]+)=\d+\t" max_match=10 | stats count by myFields&lt;/MYFIELDS&gt;&lt;/P&gt;

&lt;P&gt;Though this isn't as general as the accepted answer nor probably as fast.&lt;/P&gt;</description>
      <pubDate>Mon, 28 Sep 2020 10:09:50 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/stats-on-the-presence-of-a-field/m-p/24028#M4367</guid>
      <dc:creator>Samslara</dc:creator>
      <dc:date>2020-09-28T10:09:50Z</dc:date>
    </item>
  </channel>
</rss>

