<?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: How do I extract numerical value from within a string using rex command? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-do-I-extract-numerical-value-from-within-a-string-using-rex/m-p/247456#M73826</link>
    <description>&lt;P&gt;Exactly that!  I saw that you revised your answer since I was about to say that I added the \s so that it would take everything after the space, but I see you caught that already!&lt;/P&gt;

&lt;P&gt;Thank you!&lt;/P&gt;</description>
    <pubDate>Sun, 27 Nov 2016 00:05:55 GMT</pubDate>
    <dc:creator>andrewtrobec</dc:creator>
    <dc:date>2016-11-27T00:05:55Z</dc:date>
    <item>
      <title>How do I extract numerical value from within a string using rex command?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-I-extract-numerical-value-from-within-a-string-using-rex/m-p/247454#M73824</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;

&lt;P&gt;I've been reading up on the &lt;CODE&gt;rex&lt;/CODE&gt; command and using it to split strings, but I cannot for the life of me get it working.  I have the following input:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;FORECAST
Sun and a few passing clouds. High 13C. Winds light and variable.
Partly cloudy. Low 4C. Winds light and variable.
Overcast with rain showers at times. High around 10C. Winds NE at 10 to 15 km/h. Chance of rain 60%.
Cloudy skies. Low 2C. Winds ENE at 10 to 15 km/h.
Partly cloudy skies. High 6C. Winds light and variable.
A mostly clear sky. Low -1C. Winds light and variable.
A mainly sunny sky. High 6C. Winds light and variable.
A mostly clear sky. Low near 0C. Winds light and variable.
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;and my goal is to extract the temperature value into a new field FORECAST_C.  I basically have to remove everything up until the space between the date, and everything after starting with "C.".  My desired output is:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;FORECAST_C
13
4
10
2
6
-1
6
0
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;I've come up with&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;rex field=entry ".\s(&amp;lt;FORECAST_C&amp;gt;.*)C\w."
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;but it's clearly not working...&lt;/P&gt;

&lt;P&gt;Can somebody give me a hand?&lt;/P&gt;

&lt;P&gt;Thanks!&lt;/P&gt;

&lt;P&gt;Andrew&lt;/P&gt;</description>
      <pubDate>Sat, 26 Nov 2016 23:23:17 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-I-extract-numerical-value-from-within-a-string-using-rex/m-p/247454#M73824</guid>
      <dc:creator>andrewtrobec</dc:creator>
      <dc:date>2016-11-26T23:23:17Z</dc:date>
    </item>
    <item>
      <title>Re: How do I extract numerical value from within a string using rex command?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-I-extract-numerical-value-from-within-a-string-using-rex/m-p/247455#M73825</link>
      <description>&lt;P&gt;If every line is an event try this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;your query to return event
| rex field=_raw ".*\s(?&amp;lt;FORECAST_C&amp;gt;\-*[\d]+)C\..*"
| table FORECAST_C
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;If more than one lines are in per event try &lt;CODE&gt;max_match=0&lt;/CODE&gt; in it:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;your query to return event
| rex max_match=0 field=_raw ".*\s(?&amp;lt;FORECAST_C&amp;gt;\-*[\d]+)C\..*"
| table FORECAST_C
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;If the data in question is in &lt;CODE&gt;field=entry&lt;/CODE&gt; then you can use that field as well in the above commands rather than &lt;CODE&gt;field=_raw&lt;/CODE&gt;.&lt;/P&gt;

&lt;P&gt;&lt;A href="https://regex101.com/r/glyRO2/2"&gt;See extraction here.&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Sat, 26 Nov 2016 23:55:03 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-I-extract-numerical-value-from-within-a-string-using-rex/m-p/247455#M73825</guid>
      <dc:creator>gokadroid</dc:creator>
      <dc:date>2016-11-26T23:55:03Z</dc:date>
    </item>
    <item>
      <title>Re: How do I extract numerical value from within a string using rex command?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-I-extract-numerical-value-from-within-a-string-using-rex/m-p/247456#M73826</link>
      <description>&lt;P&gt;Exactly that!  I saw that you revised your answer since I was about to say that I added the \s so that it would take everything after the space, but I see you caught that already!&lt;/P&gt;

&lt;P&gt;Thank you!&lt;/P&gt;</description>
      <pubDate>Sun, 27 Nov 2016 00:05:55 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-I-extract-numerical-value-from-within-a-string-using-rex/m-p/247456#M73826</guid>
      <dc:creator>andrewtrobec</dc:creator>
      <dc:date>2016-11-27T00:05:55Z</dc:date>
    </item>
  </channel>
</rss>

