<?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 How to count sequence of strings in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-to-count-sequence-of-strings/m-p/100431#M25952</link>
    <description>&lt;P&gt;I have the following log:&lt;/P&gt;

&lt;P&gt;01/02/2011:00:00:01 q=UP &lt;BR /&gt;
01/02/2011:00:00:02 q=UP A &lt;BR /&gt;
01/02/2011:00:00:03 q=UP AL &lt;BR /&gt;
01/02/2011:00:00:04 q=UP ALF &lt;BR /&gt;
01/02/2011:00:00:05 q=UP ALL &lt;/P&gt;

&lt;P&gt;And I would like to have these result set:&lt;/P&gt;

&lt;P&gt;q   COunt&lt;BR /&gt;
UP ALF  1&lt;BR /&gt;
UP ALL  1&lt;/P&gt;

&lt;P&gt;Any ideas?&lt;BR /&gt;
Thanks&lt;/P&gt;</description>
    <pubDate>Fri, 28 Oct 2011 19:02:30 GMT</pubDate>
    <dc:creator>lpolo</dc:creator>
    <dc:date>2011-10-28T19:02:30Z</dc:date>
    <item>
      <title>How to count sequence of strings</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-count-sequence-of-strings/m-p/100431#M25952</link>
      <description>&lt;P&gt;I have the following log:&lt;/P&gt;

&lt;P&gt;01/02/2011:00:00:01 q=UP &lt;BR /&gt;
01/02/2011:00:00:02 q=UP A &lt;BR /&gt;
01/02/2011:00:00:03 q=UP AL &lt;BR /&gt;
01/02/2011:00:00:04 q=UP ALF &lt;BR /&gt;
01/02/2011:00:00:05 q=UP ALL &lt;/P&gt;

&lt;P&gt;And I would like to have these result set:&lt;/P&gt;

&lt;P&gt;q   COunt&lt;BR /&gt;
UP ALF  1&lt;BR /&gt;
UP ALL  1&lt;/P&gt;

&lt;P&gt;Any ideas?&lt;BR /&gt;
Thanks&lt;/P&gt;</description>
      <pubDate>Fri, 28 Oct 2011 19:02:30 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-count-sequence-of-strings/m-p/100431#M25952</guid>
      <dc:creator>lpolo</dc:creator>
      <dc:date>2011-10-28T19:02:30Z</dc:date>
    </item>
    <item>
      <title>Re: How to count sequence of strings</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-count-sequence-of-strings/m-p/100432#M25953</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;

&lt;P&gt;Is that your actual log, or just a sample of what the log &lt;EM&gt;could&lt;/EM&gt; look like? Do the log messages end just after A, AL or ALF etc?&lt;/P&gt;

&lt;P&gt;Not 100% sure of the output you want either. Are you only interested in the count of events for ALF and ALL, but not for A or AL?&lt;/P&gt;

&lt;P&gt;Are you familiar with field extractions? &lt;/P&gt;

&lt;P&gt;Yes, I have ideas, but some more info would be good.&lt;/P&gt;

&lt;P&gt;/kristian&lt;/P&gt;</description>
      <pubDate>Fri, 28 Oct 2011 19:20:11 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-count-sequence-of-strings/m-p/100432#M25953</guid>
      <dc:creator>kristian_kolb</dc:creator>
      <dc:date>2011-10-28T19:20:11Z</dc:date>
    </item>
    <item>
      <title>Re: How to count sequence of strings</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-count-sequence-of-strings/m-p/100433#M25954</link>
      <description>&lt;P&gt;That is the actual log. q is a set of query searches. In this example the user typed q in the sequence I presented as a result the intention of the user was UP ALF. Then another user typed UP ALL. &lt;BR /&gt;
q can be any string.&lt;/P&gt;

&lt;P&gt;Thanks&lt;/P&gt;</description>
      <pubDate>Sat, 29 Oct 2011 01:20:48 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-count-sequence-of-strings/m-p/100433#M25954</guid>
      <dc:creator>lpolo</dc:creator>
      <dc:date>2011-10-29T01:20:48Z</dc:date>
    </item>
    <item>
      <title>Re: How to count sequence of strings</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-count-sequence-of-strings/m-p/100434#M25955</link>
      <description>&lt;P&gt;Assuming you always want &lt;EM&gt;everything&lt;/EM&gt; after the equals sign, it's pretty straightforward:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;...
| rex field="_raw" "q=(?&amp;lt;querystring&amp;gt;.*)"
| stats count by querystring
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Or, you can set up a more permanent field extraction as below, and then use &lt;CODE&gt;stats&lt;/CODE&gt; without the &lt;CODE&gt;rex&lt;/CODE&gt; command:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;#In transforms.conf...
[qstring]
REGEX = q=(.*)
FORMAT = querystring::$1

#In props.conf...
[putYourSourcetypeHere]
REPORT-qstring = qstring
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;(search for &lt;CODE&gt;... | stats count by querystring&lt;/CODE&gt; )&lt;/P&gt;</description>
      <pubDate>Sat, 29 Oct 2011 01:43:37 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-count-sequence-of-strings/m-p/100434#M25955</guid>
      <dc:creator>southeringtonp</dc:creator>
      <dc:date>2011-10-29T01:43:37Z</dc:date>
    </item>
    <item>
      <title>Re: How to count sequence of strings</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-count-sequence-of-strings/m-p/100435#M25956</link>
      <description>&lt;P&gt;You should extract the &lt;CODE&gt;q&lt;/CODE&gt; field by adding to/creating your stanza for the source/sourcetype in &lt;CODE&gt;props.conf&lt;/CODE&gt; &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;[your_source_or_sourcetype_here]
EXTRACT-q_string = \sq=(?&amp;lt;qstring&amp;gt;.*)$
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Then you can have a search like&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;... | stats count AS Count by qstring | addcoltotals Count labelfield=qstring label="Total no. queries" 
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Which should give you;&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;qstring             Count
--------------------------
UP                      6
UP ALL                  4
UP AF                   2
Total no. queries      12
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;EDIT: typo in the field extraction.. &lt;/P&gt;

&lt;P&gt;Hope this helps,&lt;/P&gt;

&lt;P&gt;Kristian &lt;/P&gt;</description>
      <pubDate>Sat, 29 Oct 2011 09:36:12 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-count-sequence-of-strings/m-p/100435#M25956</guid>
      <dc:creator>kristian_kolb</dc:creator>
      <dc:date>2011-10-29T09:36:12Z</dc:date>
    </item>
    <item>
      <title>Re: How to count sequence of strings</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-count-sequence-of-strings/m-p/100436#M25957</link>
      <description>&lt;P&gt;Thanks for your response. The issue is not about how extract the value of q.&lt;/P&gt;</description>
      <pubDate>Sun, 30 Oct 2011 02:29:33 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-count-sequence-of-strings/m-p/100436#M25957</guid>
      <dc:creator>lpolo</dc:creator>
      <dc:date>2011-10-30T02:29:33Z</dc:date>
    </item>
    <item>
      <title>Re: How to count sequence of strings</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-count-sequence-of-strings/m-p/100437#M25958</link>
      <description>&lt;P&gt;It does not work... The query does not return the result set I presented in the example.....&lt;/P&gt;

&lt;P&gt;Thanks,&lt;/P&gt;</description>
      <pubDate>Sun, 30 Oct 2011 02:34:18 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-count-sequence-of-strings/m-p/100437#M25958</guid>
      <dc:creator>lpolo</dc:creator>
      <dc:date>2011-10-30T02:34:18Z</dc:date>
    </item>
    <item>
      <title>Re: How to count sequence of strings</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-count-sequence-of-strings/m-p/100438#M25959</link>
      <description>&lt;P&gt;After some work I think that this query does the work:&lt;/P&gt;

&lt;P&gt;sourcetype="queries" q NOT NULL | &lt;BR /&gt;
 eval q=upper(q) | &lt;BR /&gt;
 eval QueryFirstLetter=substr(q,1,1) | &lt;BR /&gt;
 transaction maxpause=0s QueryFirstLetter delim="," mvlist=q | &lt;BR /&gt;
 eval Query=mvindex(q, -1) | &lt;BR /&gt;
 top limit=0 Query &lt;/P&gt;</description>
      <pubDate>Sun, 30 Oct 2011 02:41:26 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-count-sequence-of-strings/m-p/100438#M25959</guid>
      <dc:creator>lpolo</dc:creator>
      <dc:date>2011-10-30T02:41:26Z</dc:date>
    </item>
    <item>
      <title>Re: How to count sequence of strings</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-count-sequence-of-strings/m-p/100439#M25960</link>
      <description>&lt;P&gt;Well, what results did you get?&lt;/P&gt;

&lt;P&gt;/k&lt;/P&gt;</description>
      <pubDate>Thu, 10 Nov 2011 12:43:34 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-count-sequence-of-strings/m-p/100439#M25960</guid>
      <dc:creator>kristian_kolb</dc:creator>
      <dc:date>2011-11-10T12:43:34Z</dc:date>
    </item>
    <item>
      <title>Re: How to count sequence of strings</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-count-sequence-of-strings/m-p/100440#M25961</link>
      <description>&lt;P&gt;This query is working fine but If I select a large time period it fails. I will update this notes once I have more information.&lt;/P&gt;</description>
      <pubDate>Thu, 10 Nov 2011 16:15:13 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-count-sequence-of-strings/m-p/100440#M25961</guid>
      <dc:creator>lpolo</dc:creator>
      <dc:date>2011-11-10T16:15:13Z</dc:date>
    </item>
    <item>
      <title>Re: How to count sequence of strings</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-count-sequence-of-strings/m-p/100441#M25962</link>
      <description>&lt;P&gt;I replace the top command by stats. Now it is working.&lt;/P&gt;

&lt;P&gt;sourcetype="queries" q NOT NULL | &lt;BR /&gt;
 eval q=upper(q) | &lt;BR /&gt;
 eval QueryFirstLetter=substr(q,1,1) | &lt;BR /&gt;
 transaction maxpause=0s QueryFirstLetter delim="," mvlist=q | &lt;BR /&gt;
 eval Query=mvindex(q, -1) | &lt;BR /&gt;
 stats count by Query|sort - Query&lt;/P&gt;</description>
      <pubDate>Thu, 10 Nov 2011 18:46:21 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-count-sequence-of-strings/m-p/100441#M25962</guid>
      <dc:creator>lpolo</dc:creator>
      <dc:date>2011-11-10T18:46:21Z</dc:date>
    </item>
  </channel>
</rss>

