<?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 do you use the rex command to calculate a value? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-do-you-use-the-rex-command-to-calculate-a-value/m-p/398527#M115578</link>
    <description>&lt;P&gt;Hello,&lt;/P&gt;

&lt;P&gt;I'm new to Splunk and I have the following field and want to grab the subtotal of the field total using the rex_raw field.&lt;/P&gt;

&lt;P&gt;This is the field in the log file&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt; "total"=&amp;gt;"$37.05",
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;This is the code I wrote any idea why it's not working?&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index="test" "Splunktest" "Refund succeeded" "current_cty_domain : US"  | rex  field=_raw "total\"=&amp;gt;\"$\"(?&amp;lt;refund_amount&amp;gt;.*)\"" | stats sum(refund_amount) as amount_refunded
&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Wed, 20 Jun 2018 20:36:33 GMT</pubDate>
    <dc:creator>Danielle2018V</dc:creator>
    <dc:date>2018-06-20T20:36:33Z</dc:date>
    <item>
      <title>How do you use the rex command to calculate a value?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-you-use-the-rex-command-to-calculate-a-value/m-p/398527#M115578</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;

&lt;P&gt;I'm new to Splunk and I have the following field and want to grab the subtotal of the field total using the rex_raw field.&lt;/P&gt;

&lt;P&gt;This is the field in the log file&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt; "total"=&amp;gt;"$37.05",
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;This is the code I wrote any idea why it's not working?&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index="test" "Splunktest" "Refund succeeded" "current_cty_domain : US"  | rex  field=_raw "total\"=&amp;gt;\"$\"(?&amp;lt;refund_amount&amp;gt;.*)\"" | stats sum(refund_amount) as amount_refunded
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 20 Jun 2018 20:36:33 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-you-use-the-rex-command-to-calculate-a-value/m-p/398527#M115578</guid>
      <dc:creator>Danielle2018V</dc:creator>
      <dc:date>2018-06-20T20:36:33Z</dc:date>
    </item>
    <item>
      <title>Re: How do you use the rex command to calculate a value?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-you-use-the-rex-command-to-calculate-a-value/m-p/398528#M115579</link>
      <description>&lt;P&gt;Hey..    &lt;/P&gt;

&lt;P&gt;You didn't make any fields in your regular expression.   For rex to work you need to have a regular expression with at least one named capture group    like:  (?pattern)&lt;/P&gt;

&lt;P&gt;try something like: &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index="test" "Splunktest" "Refund succeeded" "current_cty_domain : US" 
| rex field=_raw "total\"=&amp;gt;\"$(?&amp;lt;refund_amount&amp;gt;[^\"]+)\"" 
| stats sum(refund_amount) as amount_refunded
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 20 Jun 2018 20:55:50 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-you-use-the-rex-command-to-calculate-a-value/m-p/398528#M115579</guid>
      <dc:creator>darrenfuller</dc:creator>
      <dc:date>2018-06-20T20:55:50Z</dc:date>
    </item>
    <item>
      <title>Re: How do you use the rex command to calculate a value?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-you-use-the-rex-command-to-calculate-a-value/m-p/398529#M115580</link>
      <description>&lt;P&gt;Something like - &lt;CODE&gt;"total"=&amp;gt;\$(?&amp;lt;sum&amp;gt;.*)&lt;/CODE&gt;&lt;/P&gt;

&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper" image-alt="alt text"&gt;&lt;img src="https://community.splunk.com/t5/image/serverpage/image-id/5248i69EF61B7C8CDDAF5/image-size/large?v=v2&amp;amp;px=999" role="button" title="alt text" alt="alt text" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 20 Jun 2018 20:56:15 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-you-use-the-rex-command-to-calculate-a-value/m-p/398529#M115580</guid>
      <dc:creator>ddrillic</dc:creator>
      <dc:date>2018-06-20T20:56:15Z</dc:date>
    </item>
    <item>
      <title>Re: How do you use the rex command to calculate a value?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-you-use-the-rex-command-to-calculate-a-value/m-p/398530#M115581</link>
      <description>&lt;P&gt;Try this &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index="test" "Splunktest" "Refund succeeded" "current_cty_domain : US" 
| rex  field=_raw "total\"\=\&amp;gt;\"\$(?&amp;lt;refund_amount&amp;gt;.*)\""
 | stats sum(refund_amount) as amount_refunded
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;See this runanywhere sample search&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| gentimes start=-1 | eval _raw="Somes other test  \"total\"=&amp;gt;\"$37.05\", more text" | table _raw | rex  field=_raw "total\"\=\&amp;gt;\"\$(?&amp;lt;refund_amount&amp;gt;.*)\""
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 20 Jun 2018 21:07:13 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-you-use-the-rex-command-to-calculate-a-value/m-p/398530#M115581</guid>
      <dc:creator>somesoni2</dc:creator>
      <dc:date>2018-06-20T21:07:13Z</dc:date>
    </item>
    <item>
      <title>Re: How do you use the rex command to calculate a value?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-you-use-the-rex-command-to-calculate-a-value/m-p/398531#M115582</link>
      <description>&lt;P&gt;Thanks everyone for the speedy responses. I tried all three suggestions  but still received the same error "no results found".  Below is a sample of the log file. You can see that the total is $52.99 but still no results were found.Is the rex command the most appropriate solution to gather a subtotal of the total field?&lt;/P&gt;

&lt;P&gt;Thanks &lt;/P&gt;

&lt;BLOCKQUOTE&gt;
&lt;P&gt;"$0.00", "raw_discount"=&amp;gt;0, "shipping_cost"=&amp;gt;"$0.00", "shipping_total"=&amp;gt;0, "tax"=&amp;gt;"$3.00", "occupancy_tax"=&amp;gt;nil, "tip"=&amp;gt;nil, "goods_customs_duty"=&amp;gt;"$0.00", "tax_total"=&amp;gt;3.0, "partial_refund"=&amp;gt;nil, "gift_wrapped_item_count_display"=&amp;gt;"(0)", "gift_wrap_fee_total"=&amp;gt;"$0.00", "total"=&amp;gt;"$52.99", "raw_total"=&amp;gt;52.99, "currency_code"=&amp;gt;"$", "collected"=&amp;gt;0, "collected_cash"=&amp;gt;0, "collected_bucks"=&amp;gt;0, "collected_exchange&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;</description>
      <pubDate>Tue, 29 Sep 2020 20:06:44 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-you-use-the-rex-command-to-calculate-a-value/m-p/398531#M115582</guid>
      <dc:creator>Danielle2018V</dc:creator>
      <dc:date>2020-09-29T20:06:44Z</dc:date>
    </item>
    <item>
      <title>Re: How do you use the rex command to calculate a value?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-you-use-the-rex-command-to-calculate-a-value/m-p/398532#M115583</link>
      <description>&lt;P&gt;I tried this also and got the same result, Is the rex command the most appropriate solution to gather a subtotal of the total field?&lt;/P&gt;

&lt;P&gt;Below sample log data&lt;/P&gt;

&lt;P&gt;$0.00", "raw_discount"=&amp;gt;0, "shipping_cost"=&amp;gt;"$0.00", "shipping_total"=&amp;gt;0, "tax"=&amp;gt;"$3.00", "occupancy_tax"=&amp;gt;nil, "tip"=&amp;gt;nil, "goods_customs_duty"=&amp;gt;"$0.00", "tax_total"=&amp;gt;3.0, "partial_refund"=&amp;gt;nil, "gift_wrapped_item_count_display"=&amp;gt;"(0)", "gift_wrap_fee_total"=&amp;gt;"$0.00", "total"=&amp;gt;"$52.99", "raw_total"=&amp;gt;52.99, "currency_code"=&amp;gt;"$", "collected"=&amp;gt;0, "collected_cash"=&amp;gt;0, "collected_bucks"=&amp;gt;0, "collected_exchange&lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2020 20:06:46 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-you-use-the-rex-command-to-calculate-a-value/m-p/398532#M115583</guid>
      <dc:creator>Danielle2018V</dc:creator>
      <dc:date>2020-09-29T20:06:46Z</dc:date>
    </item>
    <item>
      <title>Re: How do you use the rex command to calculate a value?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-you-use-the-rex-command-to-calculate-a-value/m-p/398533#M115584</link>
      <description>&lt;P&gt;I was able to get it to work with a combination of all answers above. &lt;/P&gt;

&lt;P&gt;rex  field=_raw "total\"=&amp;gt;\"-\$(?[^\"]+)\""&lt;/P&gt;</description>
      <pubDate>Fri, 22 Jun 2018 16:47:05 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-you-use-the-rex-command-to-calculate-a-value/m-p/398533#M115584</guid>
      <dc:creator>Danielle2018V</dc:creator>
      <dc:date>2018-06-22T16:47:05Z</dc:date>
    </item>
  </channel>
</rss>

