<?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 Grouping Wildcarded Ranges Together in Chart Results in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Grouping-Wildcarded-Ranges-Together-in-Chart-Results/m-p/126626#M34293</link>
    <description>&lt;P&gt;Hi, I feel like this is a deceptively simple question, but I'm fairly new to Splunk.&lt;/P&gt;

&lt;P&gt;I want to find the avg transaction times by country.&lt;BR /&gt;
The country is stored as "country=CO3" where CO can be any two-letter code and the numbers can be 1 digit, 2 digit, or 0 digit (in which case it's COL for Colombia).&lt;/P&gt;

&lt;P&gt;When I run the following query: &lt;CODE&gt;sourcetype="xxx" (country="CO*" OR country="VE*" OR country="PE*") | transaction transID | chart avg(duration) by country&lt;/CODE&gt;&lt;/P&gt;

&lt;P&gt;I get exactly the results I want except each version of COx is treated as a unique country (how I expect Splunk would work). I'd like to collapse the results into just the countries themselves - CO1, CO2, CO13, and COL would all show together as Colombia (naming not important).&lt;/P&gt;

&lt;P&gt;I've tried various eval statements (including the examples for earthquake magnitudes here: &lt;A href="http://docs.splunk.com/Documentation/Splunk/6.0/SearchReference/eval"&gt;http://docs.splunk.com/Documentation/Splunk/6.0/SearchReference/eval&lt;/A&gt;) but can't seem to get it working with strings.&lt;/P&gt;

&lt;P&gt;Can someone explain how to collapse the string results into countries?&lt;BR /&gt;
Thanks.&lt;/P&gt;</description>
    <pubDate>Fri, 01 Nov 2013 18:46:12 GMT</pubDate>
    <dc:creator>RMartinezDTV</dc:creator>
    <dc:date>2013-11-01T18:46:12Z</dc:date>
    <item>
      <title>Grouping Wildcarded Ranges Together in Chart Results</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Grouping-Wildcarded-Ranges-Together-in-Chart-Results/m-p/126626#M34293</link>
      <description>&lt;P&gt;Hi, I feel like this is a deceptively simple question, but I'm fairly new to Splunk.&lt;/P&gt;

&lt;P&gt;I want to find the avg transaction times by country.&lt;BR /&gt;
The country is stored as "country=CO3" where CO can be any two-letter code and the numbers can be 1 digit, 2 digit, or 0 digit (in which case it's COL for Colombia).&lt;/P&gt;

&lt;P&gt;When I run the following query: &lt;CODE&gt;sourcetype="xxx" (country="CO*" OR country="VE*" OR country="PE*") | transaction transID | chart avg(duration) by country&lt;/CODE&gt;&lt;/P&gt;

&lt;P&gt;I get exactly the results I want except each version of COx is treated as a unique country (how I expect Splunk would work). I'd like to collapse the results into just the countries themselves - CO1, CO2, CO13, and COL would all show together as Colombia (naming not important).&lt;/P&gt;

&lt;P&gt;I've tried various eval statements (including the examples for earthquake magnitudes here: &lt;A href="http://docs.splunk.com/Documentation/Splunk/6.0/SearchReference/eval"&gt;http://docs.splunk.com/Documentation/Splunk/6.0/SearchReference/eval&lt;/A&gt;) but can't seem to get it working with strings.&lt;/P&gt;

&lt;P&gt;Can someone explain how to collapse the string results into countries?&lt;BR /&gt;
Thanks.&lt;/P&gt;</description>
      <pubDate>Fri, 01 Nov 2013 18:46:12 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Grouping-Wildcarded-Ranges-Together-in-Chart-Results/m-p/126626#M34293</guid>
      <dc:creator>RMartinezDTV</dc:creator>
      <dc:date>2013-11-01T18:46:12Z</dc:date>
    </item>
    <item>
      <title>Re: Grouping Wildcarded Ranges Together in Chart Results</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Grouping-Wildcarded-Ranges-Together-in-Chart-Results/m-p/126627#M34294</link>
      <description>&lt;P&gt;Please try the following&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;sourcetype="xxx" (country="CO*" OR country="VE*" OR country="PE*") | eval country=replace(country,"\d","") | transaction transID | chart avg(duration) by country
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Using this you will get country as just characters (digits removed) and it will group all CO* as one events.&lt;BR /&gt;
Hope this helps.&lt;/P&gt;

&lt;P&gt;----------------------------Update--------------------------&lt;/P&gt;

&lt;P&gt;This should be perfect for you now &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;

&lt;P&gt;sourcetype="xxx" (country="CO*" OR country="VE*" OR country="PE*") | eval extraChar=substr(country,3)| eval country=replace(country,extraChar,"") | transaction transID | chart avg(duration) by country&lt;/P&gt;</description>
      <pubDate>Mon, 28 Sep 2020 15:10:57 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Grouping-Wildcarded-Ranges-Together-in-Chart-Results/m-p/126627#M34294</guid>
      <dc:creator>somesoni2</dc:creator>
      <dc:date>2020-09-28T15:10:57Z</dc:date>
    </item>
    <item>
      <title>Re: Grouping Wildcarded Ranges Together in Chart Results</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Grouping-Wildcarded-Ranges-Together-in-Chart-Results/m-p/126628#M34295</link>
      <description>&lt;P&gt;That's definitely an improvement over the case statement I was attempting. One further question if you can help....The "first" item isn't written as CO1 but rather COL. So we have COL, CO2, CO3, etc. Is there a way to get only the first say two characters? That would programatically solve this problem. I see trim functions but my output can be either 3 or 4 (eg CO15) characters.&lt;/P&gt;</description>
      <pubDate>Fri, 01 Nov 2013 21:23:46 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Grouping-Wildcarded-Ranges-Together-in-Chart-Results/m-p/126628#M34295</guid>
      <dc:creator>RMartinezDTV</dc:creator>
      <dc:date>2013-11-01T21:23:46Z</dc:date>
    </item>
    <item>
      <title>Re: Grouping Wildcarded Ranges Together in Chart Results</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Grouping-Wildcarded-Ranges-Together-in-Chart-Results/m-p/126629#M34296</link>
      <description>&lt;P&gt;Please see the updated answer if that suits your requirement.&lt;/P&gt;</description>
      <pubDate>Fri, 01 Nov 2013 22:51:38 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Grouping-Wildcarded-Ranges-Together-in-Chart-Results/m-p/126629#M34296</guid>
      <dc:creator>somesoni2</dc:creator>
      <dc:date>2013-11-01T22:51:38Z</dc:date>
    </item>
    <item>
      <title>Re: Grouping Wildcarded Ranges Together in Chart Results</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Grouping-Wildcarded-Ranges-Together-in-Chart-Results/m-p/126630#M34297</link>
      <description>&lt;P&gt;There are plenty of ways to go about it, rex is one way but then I am partial to regular expressions.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;sourcetype="xxx" (country="CO*" OR country="VE*" OR country="PE*") 
| rex field=country "^(?&amp;lt;country_code&amp;gt;[A-Z]*)"
|  ... 
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;The rex clause will extract the 2 digit country code into a new field called &lt;EM&gt;country_code&lt;/EM&gt;.&lt;/P&gt;

&lt;P&gt;BTW, I am not sure if you actually want to use the &lt;EM&gt;transaction&lt;/EM&gt; command in your query - &lt;EM&gt;transaction&lt;/EM&gt; will merge all log entries with the same transID into one big entry and I am not sure what avg will actually be returning in this case as there are multiple records which might have multiple duration fields. &lt;BR /&gt;
One thing is for sure - &lt;EM&gt;transaction&lt;/EM&gt; makes queries really slow when there's a fair amount of data involved so if you simply need the average duration per log entry and split by country code you wouldn't need it.&lt;/P&gt;</description>
      <pubDate>Sat, 02 Nov 2013 00:24:45 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Grouping-Wildcarded-Ranges-Together-in-Chart-Results/m-p/126630#M34297</guid>
      <dc:creator>tpflicke</dc:creator>
      <dc:date>2013-11-02T00:24:45Z</dc:date>
    </item>
  </channel>
</rss>

