<?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: evaluate mathematical expression in string in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/evaluate-mathematical-expression-in-string/m-p/418527#M169205</link>
    <description>&lt;P&gt;Hmm, I just played with&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;base search | makemv delim="," rl | stats sum(rl) as total values(answertime) as answertime values(whateverIwanttokeep) as whatever by _raw | fields - _raw
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;That might be faster than my eventstats approach.&lt;/P&gt;

&lt;P&gt;A simple function to evaluate a string with math in it does not seem to exist. &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
    <pubDate>Fri, 25 May 2018 11:48:37 GMT</pubDate>
    <dc:creator>knielsen</dc:creator>
    <dc:date>2018-05-25T11:48:37Z</dc:date>
    <item>
      <title>evaluate mathematical expression in string</title>
      <link>https://community.splunk.com/t5/Splunk-Search/evaluate-mathematical-expression-in-string/m-p/418524#M169202</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;

&lt;P&gt;Is there a fast way of evaluating the result a string like "42 + 23" as a new field?&lt;/P&gt;

&lt;P&gt;Background: a log file that contains answer time and a list of lengths. I want to calculate the p98(answer time) by summed lengths of events. Right now I'm doing the &lt;CODE&gt;eval id=_cd+splunk_server | makemv delim="," rl_list | eventstats sum(rl_list) as total_rl by id&lt;/CODE&gt; trick, but I'm wondering if there is a better solution to get a sum of list elements per event.&lt;/P&gt;

&lt;P&gt;Thanks,&lt;BR /&gt;
Kai.&lt;/P&gt;</description>
      <pubDate>Fri, 25 May 2018 09:33:49 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/evaluate-mathematical-expression-in-string/m-p/418524#M169202</guid>
      <dc:creator>knielsen</dc:creator>
      <dc:date>2018-05-25T09:33:49Z</dc:date>
    </item>
    <item>
      <title>Re: evaluate mathematical expression in string</title>
      <link>https://community.splunk.com/t5/Splunk-Search/evaluate-mathematical-expression-in-string/m-p/418525#M169203</link>
      <description>&lt;P&gt;@knielsen, your query, data and question seem to be confusing. Can you add more details? Whatis the field name of string that has data like &lt;CODE&gt;"42+23"&lt;/CODE&gt;? Based on what you have asked in your question if you just want the sum of a string expression, you would need to create a &lt;CODE&gt;return&lt;/CODE&gt; like below&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| makeresults 
| eval result= 
    [| makeresults 
    | eval data="43+23" 
    | return $data ]
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 25 May 2018 10:41:56 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/evaluate-mathematical-expression-in-string/m-p/418525#M169203</guid>
      <dc:creator>niketn</dc:creator>
      <dc:date>2018-05-25T10:41:56Z</dc:date>
    </item>
    <item>
      <title>Re: evaluate mathematical expression in string</title>
      <link>https://community.splunk.com/t5/Splunk-Search/evaluate-mathematical-expression-in-string/m-p/418526#M169204</link>
      <description>&lt;P&gt;Hmm, I can't make your result work in a real search. I don't have the value data in inner search right?&lt;/P&gt;

&lt;P&gt;Ok, sometimes I speak gibberish. Back: my events have a string field, let's keep it short, "rl". This contains either one integer or a list of comma separated integers. I want to calculate the total of that list for each event and keep other fields of the event as well.&lt;/P&gt;

&lt;P&gt;Since I can convert the comma separated "1,2,3,4,5..." with rex or replace into "1+2+3+4+5+6...." I was wondering if there is a simple way to feed that string into a function to get the total.&lt;/P&gt;</description>
      <pubDate>Fri, 25 May 2018 11:00:38 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/evaluate-mathematical-expression-in-string/m-p/418526#M169204</guid>
      <dc:creator>knielsen</dc:creator>
      <dc:date>2018-05-25T11:00:38Z</dc:date>
    </item>
    <item>
      <title>Re: evaluate mathematical expression in string</title>
      <link>https://community.splunk.com/t5/Splunk-Search/evaluate-mathematical-expression-in-string/m-p/418527#M169205</link>
      <description>&lt;P&gt;Hmm, I just played with&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;base search | makemv delim="," rl | stats sum(rl) as total values(answertime) as answertime values(whateverIwanttokeep) as whatever by _raw | fields - _raw
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;That might be faster than my eventstats approach.&lt;/P&gt;

&lt;P&gt;A simple function to evaluate a string with math in it does not seem to exist. &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 25 May 2018 11:48:37 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/evaluate-mathematical-expression-in-string/m-p/418527#M169205</guid>
      <dc:creator>knielsen</dc:creator>
      <dc:date>2018-05-25T11:48:37Z</dc:date>
    </item>
    <item>
      <title>Re: evaluate mathematical expression in string</title>
      <link>https://community.splunk.com/t5/Splunk-Search/evaluate-mathematical-expression-in-string/m-p/418528#M169206</link>
      <description>&lt;P&gt;If you do not want all fields , but only specific one after stats, stats(transforming) would be better than eventstats(streaming) command. You should covert your own answer and accept the same. &lt;/P&gt;

&lt;P&gt;You could have used &lt;CODE&gt;map&lt;/CODE&gt; function in my example to evaluate expression for each field passed on through map command but it would be too expensive and may hit limit as well.&lt;/P&gt;

&lt;P&gt;Also as far as a command/function not existing at present, you can definitely code Custom Commands using Python if you have the expertise.&lt;/P&gt;</description>
      <pubDate>Fri, 25 May 2018 11:54:32 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/evaluate-mathematical-expression-in-string/m-p/418528#M169206</guid>
      <dc:creator>niketn</dc:creator>
      <dc:date>2018-05-25T11:54:32Z</dc:date>
    </item>
  </channel>
</rss>

