<?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: eval to create temporary field for sorting in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/eval-to-create-temporary-field-for-sorting/m-p/368331#M108563</link>
    <description>&lt;P&gt;Hi @niketnilay and @somesoni2&lt;/P&gt;

&lt;P&gt;Thanks but it isn't working as expected its just giving me each line 6 times without calculating anything. &lt;BR /&gt;
am getting like below :&lt;BR /&gt;
CS - ierwrr her                  Null%&lt;BR /&gt;
... 6 times                           Null%&lt;BR /&gt;
CS - ierwrr her&lt;BR /&gt;
TS - defirrrr werr&lt;BR /&gt;
... 6times&lt;BR /&gt;
TS - defirrrr werr&lt;BR /&gt;
etc.&lt;/P&gt;

&lt;P&gt;if I have 2 values in data separated by ; then mvexpand is giving me 4 values in the result .. if 3 values then 6 like that. How to get single values&lt;/P&gt;

&lt;P&gt;field1 value "^TS" sum them addtotals and then rest of the rows and at the end sum total of all lines. This is what I need. &lt;/P&gt;

&lt;P&gt;And how do I add these lines now as earlier I was sorting with row number but now am sorting with pattern. &lt;BR /&gt;
 | addcoltotals label=Total labelfield=field1 | streamstats count as sno&lt;BR /&gt;
 | appendpipe [| head 7 | addcoltotals label=Total labelfield=field1 | eval keep="Y" ]&lt;/P&gt;</description>
    <pubDate>Tue, 14 Nov 2017 12:59:08 GMT</pubDate>
    <dc:creator>surekhasplunk</dc:creator>
    <dc:date>2017-11-14T12:59:08Z</dc:date>
    <item>
      <title>eval to create temporary field for sorting</title>
      <link>https://community.splunk.com/t5/Splunk-Search/eval-to-create-temporary-field-for-sorting/m-p/368326#M108558</link>
      <description>&lt;P&gt;I have a filed1 whose values are like below&lt;/P&gt;

&lt;P&gt;TS - asfdfe sdrerw&lt;BR /&gt;
TS - ieirrrr werr&lt;BR /&gt;
TS - ierr werflll&lt;BR /&gt;
BS - errriowr erer&lt;BR /&gt;
AB - erewr erer&lt;BR /&gt;
CS - ierwrr her&lt;/P&gt;

&lt;P&gt;I want to create a temporary filed to sort these values &lt;BR /&gt;
eval temp_field1= field1 where field1=TS*&lt;BR /&gt;
eval temp_field2= field1 where field1=!TS*&lt;/P&gt;

&lt;P&gt;then in my query i want to sort  temp_field1 and  temp_field2 separately.&lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2020 16:46:42 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/eval-to-create-temporary-field-for-sorting/m-p/368326#M108558</guid>
      <dc:creator>surekhasplunk</dc:creator>
      <dc:date>2020-09-29T16:46:42Z</dc:date>
    </item>
    <item>
      <title>Re: eval to create temporary field for sorting</title>
      <link>https://community.splunk.com/t5/Splunk-Search/eval-to-create-temporary-field-for-sorting/m-p/368327#M108559</link>
      <description>&lt;P&gt;The creation of temporary fields will be pretty straightforward:&lt;BR /&gt;
&lt;PRE&gt;| eval temp_field1=if(field1="TS*", field1, NULL) &lt;BR /&gt;
| eval temp_field2=if(field1="TS*", NULL, field1)&lt;/PRE&gt;&lt;/P&gt;

&lt;P&gt;And then you can sort by either field:&lt;BR /&gt;
&lt;CODE&gt;| sort temp_field1&lt;/CODE&gt; OR  &lt;CODE&gt;|sort temp_field2&lt;/CODE&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2020 16:46:44 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/eval-to-create-temporary-field-for-sorting/m-p/368327#M108559</guid>
      <dc:creator>elliotproebstel</dc:creator>
      <dc:date>2020-09-29T16:46:44Z</dc:date>
    </item>
    <item>
      <title>Re: eval to create temporary field for sorting</title>
      <link>https://community.splunk.com/t5/Splunk-Search/eval-to-create-temporary-field-for-sorting/m-p/368328#M108560</link>
      <description>&lt;P&gt;Hi surekhasplunk,&lt;BR /&gt;
did you already tested&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| eval temp_field1=if(field1=TS*,field1," "), temp_field2=if(field1!=TS*,field1," ")
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;In this way you can sort them as you like&lt;/P&gt;

&lt;P&gt;Bye.&lt;BR /&gt;
Giuseppe&lt;/P&gt;</description>
      <pubDate>Mon, 13 Nov 2017 16:20:18 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/eval-to-create-temporary-field-for-sorting/m-p/368328#M108560</guid>
      <dc:creator>gcusello</dc:creator>
      <dc:date>2017-11-13T16:20:18Z</dc:date>
    </item>
    <item>
      <title>Re: eval to create temporary field for sorting</title>
      <link>https://community.splunk.com/t5/Splunk-Search/eval-to-create-temporary-field-for-sorting/m-p/368329#M108561</link>
      <description>&lt;P&gt;You need to use either &lt;CODE&gt;match&lt;/CODE&gt; or &lt;CODE&gt;like&lt;/CODE&gt; function of eval to generate your temporary fields like this.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;your current search with field 'field1'
| eval temp_field1=if(match(field1,"^TS"),field1,null())
| eval temp_field2=if(NOT match(field1,"^TS"),field1,null())
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;OR &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;your current search with field 'field1'
| eval temp_field1=if(like(field1,"TS%"),field1,null())
| eval temp_field2=if(NOT like(field1,"TS%"),field1,null())
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Sorting can be done by any field (or in specific order of combination of those fields) using sort command.&lt;/P&gt;</description>
      <pubDate>Mon, 13 Nov 2017 16:48:39 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/eval-to-create-temporary-field-for-sorting/m-p/368329#M108561</guid>
      <dc:creator>somesoni2</dc:creator>
      <dc:date>2017-11-13T16:48:39Z</dc:date>
    </item>
    <item>
      <title>Re: eval to create temporary field for sorting</title>
      <link>https://community.splunk.com/t5/Splunk-Search/eval-to-create-temporary-field-for-sorting/m-p/368330#M108562</link>
      <description>&lt;P&gt;@surekhasplunk, I hope you are trying to &lt;CODE&gt;sort all field values containing TS first&lt;/CODE&gt; in ascending order. Then you want to add &lt;CODE&gt;remaining values sorted afterwards&lt;/CODE&gt;.&lt;/P&gt;

&lt;P&gt;Please try out the following run anywhere search based on your sample data. I have jumbled TS and other fields for testing sort.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;|  makeresults
|  eval data="CS - ierwrr her;TS - defirrrr werr;TS - abcr werflll;BS - errriowr erer;AB - derwr erer;TS - asfdfe sdrerw"
|  eval data=split(data,";")
|  mvexpand data
|  eval field1=mvindex(data,0)
|  table field1
|  sort field1
|  eval sortOverride=case(match(field1,"^TS - "),"Y",true(),"N")
|  appendpipe [| where sortOverride="N" | eval sortOverride="Y" ]
|  search sortOverride="Y"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;@somesoni2, I was so blown away by your use of &lt;CODE&gt;appendpipe&lt;/CODE&gt; yesterday that I wanted to try it myself... thanks for teaching a new trick &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 13 Nov 2017 16:51:40 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/eval-to-create-temporary-field-for-sorting/m-p/368330#M108562</guid>
      <dc:creator>niketn</dc:creator>
      <dc:date>2017-11-13T16:51:40Z</dc:date>
    </item>
    <item>
      <title>Re: eval to create temporary field for sorting</title>
      <link>https://community.splunk.com/t5/Splunk-Search/eval-to-create-temporary-field-for-sorting/m-p/368331#M108563</link>
      <description>&lt;P&gt;Hi @niketnilay and @somesoni2&lt;/P&gt;

&lt;P&gt;Thanks but it isn't working as expected its just giving me each line 6 times without calculating anything. &lt;BR /&gt;
am getting like below :&lt;BR /&gt;
CS - ierwrr her                  Null%&lt;BR /&gt;
... 6 times                           Null%&lt;BR /&gt;
CS - ierwrr her&lt;BR /&gt;
TS - defirrrr werr&lt;BR /&gt;
... 6times&lt;BR /&gt;
TS - defirrrr werr&lt;BR /&gt;
etc.&lt;/P&gt;

&lt;P&gt;if I have 2 values in data separated by ; then mvexpand is giving me 4 values in the result .. if 3 values then 6 like that. How to get single values&lt;/P&gt;

&lt;P&gt;field1 value "^TS" sum them addtotals and then rest of the rows and at the end sum total of all lines. This is what I need. &lt;/P&gt;

&lt;P&gt;And how do I add these lines now as earlier I was sorting with row number but now am sorting with pattern. &lt;BR /&gt;
 | addcoltotals label=Total labelfield=field1 | streamstats count as sno&lt;BR /&gt;
 | appendpipe [| head 7 | addcoltotals label=Total labelfield=field1 | eval keep="Y" ]&lt;/P&gt;</description>
      <pubDate>Tue, 14 Nov 2017 12:59:08 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/eval-to-create-temporary-field-for-sorting/m-p/368331#M108563</guid>
      <dc:creator>surekhasplunk</dc:creator>
      <dc:date>2017-11-14T12:59:08Z</dc:date>
    </item>
    <item>
      <title>Re: eval to create temporary field for sorting</title>
      <link>https://community.splunk.com/t5/Splunk-Search/eval-to-create-temporary-field-for-sorting/m-p/368332#M108564</link>
      <description>&lt;P&gt;@surekhasplunk, first Un-accept the answer, if your query is not resolved, so that this question flags as unanswered for other community members as well.&lt;/P&gt;

&lt;P&gt;In my run anywhere example the &lt;STRONG&gt;pipes till &lt;CODE&gt;| table field1&lt;/CODE&gt; were just used to mock sample data&lt;/STRONG&gt; as per your question. You dont need to use those pipes. &lt;/P&gt;

&lt;P&gt;You would need to write your own Splunk search query with required transforming command to output the table. Then continue with commands in the answer to be applied on &lt;CODE&gt;field1&lt;/CODE&gt; (as per the question).&lt;BR /&gt;
Please try out and confirm. Try out other answers suggested by Guiseppe and Somesh as well to see if caters to your needs and resolves your issue or not.&lt;/P&gt;</description>
      <pubDate>Tue, 14 Nov 2017 20:24:14 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/eval-to-create-temporary-field-for-sorting/m-p/368332#M108564</guid>
      <dc:creator>niketn</dc:creator>
      <dc:date>2017-11-14T20:24:14Z</dc:date>
    </item>
  </channel>
</rss>

