<?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: Sorting stats 'list' results in a certain order? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Sorting-stats-list-results-in-a-certain-order/m-p/361128#M106690</link>
    <description>&lt;P&gt;At the point that you have something like this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| stats values(severity) AS severity BY host
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Add this after it:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| rex field=severity mode=sed "s/(Critical Severity)/5:\1/ s/(High Severity)/4:\1/ s/(Medium Severity)/3:\1/ s/(Low Severity)/2:\1/ s/(Informative)/1:\1/"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Then do it again to cause it to be resorted:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| stats values(severity) AS severity BY host
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;You could do this before you do the &lt;CODE&gt;stats&lt;/CODE&gt; but then you are changing millions of events instead of a few.&lt;BR /&gt;
P.S.  Yes, this is backwards from your perfect desire but should be close enough.  If you REALLY need it the other way, then you can do this instead:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| rex field=severity mode=sed "s/(Critical Severity)/    \1/ s/(High Severity)/   \1/ s/(Medium Severity)/  \1/ s/(Low Severity)/ \1/"
&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Wed, 09 Aug 2017 23:34:17 GMT</pubDate>
    <dc:creator>woodcock</dc:creator>
    <dc:date>2017-08-09T23:34:17Z</dc:date>
    <item>
      <title>Sorting stats 'list' results in a certain order?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Sorting-stats-list-results-in-a-certain-order/m-p/361127#M106689</link>
      <description>&lt;P&gt;Hi All, Im working with some vulnerability data and I'm wondering if I can sort the list I have of different vulnerability ratings the way I want it to look. So far I have come up empty on ideas.&lt;BR /&gt;
At the moment the data is being sorted alphabetically and looks like this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;Critical Severity   
High Severity
Informative 
Low Severity
Medium Severity
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;I'd like it to look like this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;Critical Severity   
High Severity
Medium Severity
Low Severity
Informative 
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Possible?&lt;BR /&gt;
Thanks!&lt;/P&gt;</description>
      <pubDate>Wed, 09 Aug 2017 22:43:05 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Sorting-stats-list-results-in-a-certain-order/m-p/361127#M106689</guid>
      <dc:creator>mrgibbon</dc:creator>
      <dc:date>2017-08-09T22:43:05Z</dc:date>
    </item>
    <item>
      <title>Re: Sorting stats 'list' results in a certain order?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Sorting-stats-list-results-in-a-certain-order/m-p/361128#M106690</link>
      <description>&lt;P&gt;At the point that you have something like this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| stats values(severity) AS severity BY host
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Add this after it:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| rex field=severity mode=sed "s/(Critical Severity)/5:\1/ s/(High Severity)/4:\1/ s/(Medium Severity)/3:\1/ s/(Low Severity)/2:\1/ s/(Informative)/1:\1/"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Then do it again to cause it to be resorted:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| stats values(severity) AS severity BY host
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;You could do this before you do the &lt;CODE&gt;stats&lt;/CODE&gt; but then you are changing millions of events instead of a few.&lt;BR /&gt;
P.S.  Yes, this is backwards from your perfect desire but should be close enough.  If you REALLY need it the other way, then you can do this instead:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| rex field=severity mode=sed "s/(Critical Severity)/    \1/ s/(High Severity)/   \1/ s/(Medium Severity)/  \1/ s/(Low Severity)/ \1/"
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 09 Aug 2017 23:34:17 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Sorting-stats-list-results-in-a-certain-order/m-p/361128#M106690</guid>
      <dc:creator>woodcock</dc:creator>
      <dc:date>2017-08-09T23:34:17Z</dc:date>
    </item>
    <item>
      <title>Re: Sorting stats 'list' results in a certain order?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Sorting-stats-list-results-in-a-certain-order/m-p/361129#M106691</link>
      <description>&lt;P&gt;Wonderful!&lt;BR /&gt;
This worked a treat:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| eval sevdesc='severity.description'
| stats count by "Custom Tag", sevdesc 
| rex field=sevdesc mode=sed "s/(Critical Severity)/    \1/ s/(High Severity)/   \1/ s/(Medium Severity)/  \1/ s/(Low Severity)/ \1/"
| stats list(count), values(sevdesc) by "Custom Tag" 
| sort values(sevdesc), -list(count) 
| rename "Custom Tag" AS Application list(count) AS Count values(sevdesc) AS Severity 
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Thanks!&lt;/P&gt;</description>
      <pubDate>Thu, 10 Aug 2017 04:12:08 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Sorting-stats-list-results-in-a-certain-order/m-p/361129#M106691</guid>
      <dc:creator>mrgibbon</dc:creator>
      <dc:date>2017-08-10T04:12:08Z</dc:date>
    </item>
  </channel>
</rss>

