<?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 customize and sort columns with specific conditions? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-to-customize-and-sort-columns-with-specific-conditions/m-p/407898#M117787</link>
    <description>&lt;P&gt;Hi,&lt;/P&gt;

&lt;P&gt;I am looking to sort column with specific condition. &lt;/P&gt;

&lt;P&gt;Condition:&lt;BR /&gt;
if column Context_Command contains * it should be down in list and all the rows which doesn't have * in Context_Command &lt;BR /&gt;
should be up in the list. &lt;/P&gt;

&lt;P&gt;&lt;IMG src="https://community.splunk.com/storage/temp/271076-sorting-csv.png" alt="alt text" /&gt;&lt;/P&gt;</description>
    <pubDate>Wed, 30 Sep 2020 00:05:53 GMT</pubDate>
    <dc:creator>AKG1_old1</dc:creator>
    <dc:date>2020-09-30T00:05:53Z</dc:date>
    <item>
      <title>How to customize and sort columns with specific conditions?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-customize-and-sort-columns-with-specific-conditions/m-p/407898#M117787</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;

&lt;P&gt;I am looking to sort column with specific condition. &lt;/P&gt;

&lt;P&gt;Condition:&lt;BR /&gt;
if column Context_Command contains * it should be down in list and all the rows which doesn't have * in Context_Command &lt;BR /&gt;
should be up in the list. &lt;/P&gt;

&lt;P&gt;&lt;IMG src="https://community.splunk.com/storage/temp/271076-sorting-csv.png" alt="alt text" /&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 30 Sep 2020 00:05:53 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-customize-and-sort-columns-with-specific-conditions/m-p/407898#M117787</guid>
      <dc:creator>AKG1_old1</dc:creator>
      <dc:date>2020-09-30T00:05:53Z</dc:date>
    </item>
    <item>
      <title>Re: How to customize and sort columns with specific conditions?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-customize-and-sort-columns-with-specific-conditions/m-p/407899#M117788</link>
      <description>&lt;P&gt;Try adding this to your search:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;...
|eval has_star=if(match(Context_Command, "\*"), 1, 0)
|sort has_star, Context_Command 
|fields - has_star
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Here is a run-anywhere example:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| makeresults 
| eval foo="I have a *" 
| eval has_star=if(match(foo, "\*"), 1, 0) 
| append 
    [| makeresults 
    | eval foo="I don't have a star" 
    | eval has_star=if(match(foo, "\*"), 1, 0)] 
| sort has_star, foo
| fields - has_star
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Note that you have to use the &lt;CODE&gt;match&lt;/CODE&gt; command because regular expressions are the only way to match a literal wildcard. You probably already figured out that &lt;CODE&gt;Context_Command="*"&lt;/CODE&gt; doesn't work.&lt;/P&gt;</description>
      <pubDate>Mon, 15 Apr 2019 12:17:20 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-customize-and-sort-columns-with-specific-conditions/m-p/407899#M117788</guid>
      <dc:creator>grittonc</dc:creator>
      <dc:date>2019-04-15T12:17:20Z</dc:date>
    </item>
    <item>
      <title>Re: How to customize and sort columns with specific conditions?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-customize-and-sort-columns-with-specific-conditions/m-p/407900#M117789</link>
      <description>&lt;P&gt;Try something like this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;  | rex field=Context_Command "(?&amp;lt;sortingVariable&amp;gt;\*)"
| table Context_Command sortingVariable 
| fillnull
| sort -sortingVariable
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Add whatever additional fields you want to the table commands, and it should work,&lt;BR /&gt;
I tested it with this query:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| makeresults 
| eval Context_Command="*,*,23,1123*23,4224,232*2,1111,***1" 
| makemv Context_Command delim=","
| fields Context_Command
| stats count by Context_Command
| rex field=Context_Command "(?&amp;lt;sortingVariable&amp;gt;\*)"
| table Context_Command sortingVariable 
| fillnull
| sort -sortingVariable
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 15 Apr 2019 12:19:55 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-customize-and-sort-columns-with-specific-conditions/m-p/407900#M117789</guid>
      <dc:creator>martinpu</dc:creator>
      <dc:date>2019-04-15T12:19:55Z</dc:date>
    </item>
  </channel>
</rss>

