<?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 Extract and/or add numbers from a string in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Extract-and-or-add-numbers-from-a-string/m-p/679039#M232126</link>
    <description>&lt;P&gt;I have string field:&lt;/P&gt;&lt;P&gt;provTimes: a=10; b=15; c=10;&lt;/P&gt;&lt;P&gt;it basically has semicolon separated sub-fields in the value. Each sub-field has a number on right hand side.&amp;nbsp;&lt;/P&gt;&lt;P&gt;These fields are dynamic, can be a,v,e,f in 1 event and z,y in another event. Ignoring the sub field names, I'm only concerned with the numbers they have. I just want to add them all.&lt;/P&gt;&lt;P&gt;&amp;nbsp;Example&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;provTimes: a=10; b=15; c=10;&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;result = 35&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;provTimes: x=10; b=5;&lt;/P&gt;&lt;P&gt;result = 15&lt;/P&gt;</description>
    <pubDate>Wed, 28 Feb 2024 17:19:19 GMT</pubDate>
    <dc:creator>apoorvaaccount</dc:creator>
    <dc:date>2024-02-28T17:19:19Z</dc:date>
    <item>
      <title>Extract and/or add numbers from a string</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Extract-and-or-add-numbers-from-a-string/m-p/679039#M232126</link>
      <description>&lt;P&gt;I have string field:&lt;/P&gt;&lt;P&gt;provTimes: a=10; b=15; c=10;&lt;/P&gt;&lt;P&gt;it basically has semicolon separated sub-fields in the value. Each sub-field has a number on right hand side.&amp;nbsp;&lt;/P&gt;&lt;P&gt;These fields are dynamic, can be a,v,e,f in 1 event and z,y in another event. Ignoring the sub field names, I'm only concerned with the numbers they have. I just want to add them all.&lt;/P&gt;&lt;P&gt;&amp;nbsp;Example&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;provTimes: a=10; b=15; c=10;&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;result = 35&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;provTimes: x=10; b=5;&lt;/P&gt;&lt;P&gt;result = 15&lt;/P&gt;</description>
      <pubDate>Wed, 28 Feb 2024 17:19:19 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Extract-and-or-add-numbers-from-a-string/m-p/679039#M232126</guid>
      <dc:creator>apoorvaaccount</dc:creator>
      <dc:date>2024-02-28T17:19:19Z</dc:date>
    </item>
    <item>
      <title>Re: Extract and/or add numbers from a string</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Extract-and-or-add-numbers-from-a-string/m-p/679044#M232128</link>
      <description>&lt;P&gt;If you can install the mvstats app (&lt;A href="https://splunkbase.splunk.com/app/5198" target="_blank"&gt;https://splunkbase.splunk.com/app/5198&lt;/A&gt;) then this will do it.&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| rex max_match=0 "provTimes: \w+=(?&amp;lt;provTimes&amp;gt;\d+);"
| mvstats sum provTimes as result&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 28 Feb 2024 18:07:01 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Extract-and-or-add-numbers-from-a-string/m-p/679044#M232128</guid>
      <dc:creator>richgalloway</dc:creator>
      <dc:date>2024-02-28T18:07:01Z</dc:date>
    </item>
    <item>
      <title>Re: Extract and/or add numbers from a string</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Extract-and-or-add-numbers-from-a-string/m-p/679072#M232145</link>
      <description>&lt;P&gt;Or, in the old fashioned&amp;nbsp;&lt;A href="https://docs.splunk.com/Documentation/Splunk/latest/SearchReference/Extract" target="_blank" rel="noopener"&gt;extract&lt;/A&gt;&amp;nbsp;(aka kv) and &lt;A href="https://docs.splunk.com/Documentation/Splunk/latest/SearchReference/Foreach" target="_blank" rel="noopener"&gt;foreach&lt;/A&gt;&lt;span class="lia-unicode-emoji" title=":winking_face:"&gt;😉&lt;/span&gt;,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| rename _raw AS temp, provTimes AS _raw
| rex mode=sed "s/\S+=/provTimes_&amp;amp;/g"
| kv
| foreach provTimes_*
    [eval sum = mvappend(sum, '&amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt;')]
| eval sum = sum(sum)
``` below are cleanups, only if you want to restore world order ```
| fields - provTimes_*
| rex mode=sed "s/provTimes_//g"
| rename _raw AS provTimes, temp AS _raw&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here is an emulation you can play with and compare with real data&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| makeresults format=csv data="provTimes
a=10; b=15; c=10;
x=10; b=5;"
``` data emulation above ```&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Output from this emulation is&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;provTimes&lt;/TD&gt;&lt;TD&gt;sum&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;a=10; b=15; c=10;&lt;/TD&gt;&lt;TD&gt;35&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;x=10; b=5;&lt;/TD&gt;&lt;TD&gt;15&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;</description>
      <pubDate>Wed, 28 Feb 2024 22:56:26 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Extract-and-or-add-numbers-from-a-string/m-p/679072#M232145</guid>
      <dc:creator>yuanliu</dc:creator>
      <dc:date>2024-02-28T22:56:26Z</dc:date>
    </item>
  </channel>
</rss>

