<?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: Extracting values (with rex) out of the last two events and concat as one string? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Extracting-values-with-rex-out-of-the-last-two-events-and-concat/m-p/481741#M193113</link>
    <description>&lt;P&gt;Various important points have disappeared.&lt;/P&gt;

&lt;P&gt;please use code sample. &lt;CODE&gt;101010&lt;/CODE&gt;&lt;/P&gt;</description>
    <pubDate>Fri, 10 Jan 2020 12:38:02 GMT</pubDate>
    <dc:creator>to4kawa</dc:creator>
    <dc:date>2020-01-10T12:38:02Z</dc:date>
    <item>
      <title>Extracting values (with rex) out of the last two events and concat as one string?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Extracting-values-with-rex-out-of-the-last-two-events-and-concat/m-p/481740#M193112</link>
      <description>&lt;P&gt;Hey everbody &lt;/P&gt;

&lt;P&gt;I have two different evens for the same file. I need to extract the latest values and concat it to one string.&lt;/P&gt;

&lt;P&gt;File:&lt;BR /&gt;
foo=bar&lt;BR /&gt;
foo1=bar1&lt;BR /&gt;
foo2=bar2&lt;BR /&gt;
foo3=bar3&lt;/P&gt;

&lt;P&gt;Event 1:&lt;BR /&gt;
foo=new_bar&lt;BR /&gt;
foo1=new_bar1&lt;/P&gt;

&lt;P&gt;Event 2:&lt;BR /&gt;
foo2=new_bar2&lt;BR /&gt;
foo3=new_bar3&lt;/P&gt;

&lt;P&gt;Search:&lt;BR /&gt;
index=MY_INDEX sourcetype=my:source | sort - _time | head 2 | rex field=_raw "foo1=(?(.&lt;EM&gt;))" | rex field=_raw "foo2=(?(.&lt;/EM&gt;))" | table NEED1 NEED2&lt;/P&gt;

&lt;P&gt;Output:&lt;BR /&gt;
NEED1                          NEED2&lt;BR /&gt;
"" or "none"                 new_bar1&lt;BR /&gt;
"new_bar2"                  "" or "none"&lt;/P&gt;

&lt;P&gt;Expected string:&lt;BR /&gt;
new_bar2 new_bar3&lt;/P&gt;

&lt;P&gt;Is it possible?&lt;/P&gt;

&lt;P&gt;Thanks for your help.&lt;/P&gt;</description>
      <pubDate>Wed, 30 Sep 2020 03:37:45 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Extracting-values-with-rex-out-of-the-last-two-events-and-concat/m-p/481740#M193112</guid>
      <dc:creator>amatthes</dc:creator>
      <dc:date>2020-09-30T03:37:45Z</dc:date>
    </item>
    <item>
      <title>Re: Extracting values (with rex) out of the last two events and concat as one string?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Extracting-values-with-rex-out-of-the-last-two-events-and-concat/m-p/481741#M193113</link>
      <description>&lt;P&gt;Various important points have disappeared.&lt;/P&gt;

&lt;P&gt;please use code sample. &lt;CODE&gt;101010&lt;/CODE&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 10 Jan 2020 12:38:02 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Extracting-values-with-rex-out-of-the-last-two-events-and-concat/m-p/481741#M193113</guid>
      <dc:creator>to4kawa</dc:creator>
      <dc:date>2020-01-10T12:38:02Z</dc:date>
    </item>
    <item>
      <title>Re: Extracting values (with rex) out of the last two events and concat as one string?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Extracting-values-with-rex-out-of-the-last-two-events-and-concat/m-p/481742#M193114</link>
      <description>&lt;P&gt;Im not sure if  I parsed your question correctly   but based from what I understand  you want to get the 2 latest events  and  concat it with a string. Based from your  given example  your log is in  key/field=value form so that is automatically extracted . If you want to  get the latest  values it is  better to use stats,  its a lot faster and efficient  instead of using sort which is too intensive  , sorting should always be in the last.   &lt;/P&gt;

&lt;P&gt;&lt;CODE&gt;index=MY_INDEX sourcetype=my:source stats latest &lt;BR /&gt;
| stats latest(foo1) as foo1  latest(foo2) as foo2&lt;BR /&gt;
| eval NEED1="new_".foo1&lt;BR /&gt;
| eval NEED2="new_".foo2&lt;BR /&gt;
| table NEED1 NEED2&lt;/CODE&gt;&lt;/P&gt;

&lt;P&gt;Just incase you need a rex &lt;CODE&gt;|rex field=_raw "fo(\w|\w\d+)\=(?&amp;lt;value&amp;gt;[a-z0-9].*)"&lt;/CODE&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 10 Jan 2020 13:35:59 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Extracting-values-with-rex-out-of-the-last-two-events-and-concat/m-p/481742#M193114</guid>
      <dc:creator>jarizeloyola</dc:creator>
      <dc:date>2020-01-10T13:35:59Z</dc:date>
    </item>
  </channel>
</rss>

