<?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 to extract two values from two same fields in two events and then find the difference in timestamp in Getting Data In</title>
    <link>https://community.splunk.com/t5/Getting-Data-In/How-to-extract-two-values-from-two-same-fields-in-two-events-and/m-p/448538#M77964</link>
    <description>&lt;P&gt;Log data example:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;{'job_no':'1','begin_build_time':'2019-08-15 11:00:00','event_type':'staging'}
{'job_no':'1','end_build_time':'2019-08-15 11:10:00','event_type':'staging'}
{'job_no':'1','begin_execution_time':'2019-08-15 11:10:01','event_type':'transaction'}
{'job_no':'1','end_execution_time':'2019-08-15 11:20:00','event_type':'transaction'}
{'job_no':'1','begin_artifact_time':'2019-08-15 11:20:01','event_type':'upload'}
{'job_no':'1','end_artifact_time':'2019-08-15 11:30:00','event_type':'upload'}
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;I need data table output like:&lt;BR /&gt;
&lt;STRONG&gt;Job# 1 staging 10 mins  transaction 10 mins upload 10 mins total 30 mins&lt;/STRONG&gt;&lt;/P&gt;

&lt;P&gt;Each line is coming as a event in Splunk. &lt;BR /&gt;
I know we have to use coalesce and streamstats, but I am new to splunk not able to figure out how to get to this level. &lt;/P&gt;

&lt;P&gt;Thanks in advance.&lt;/P&gt;</description>
    <pubDate>Thu, 15 Aug 2019 22:05:44 GMT</pubDate>
    <dc:creator>vanakkam777</dc:creator>
    <dc:date>2019-08-15T22:05:44Z</dc:date>
    <item>
      <title>How to extract two values from two same fields in two events and then find the difference in timestamp</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/How-to-extract-two-values-from-two-same-fields-in-two-events-and/m-p/448538#M77964</link>
      <description>&lt;P&gt;Log data example:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;{'job_no':'1','begin_build_time':'2019-08-15 11:00:00','event_type':'staging'}
{'job_no':'1','end_build_time':'2019-08-15 11:10:00','event_type':'staging'}
{'job_no':'1','begin_execution_time':'2019-08-15 11:10:01','event_type':'transaction'}
{'job_no':'1','end_execution_time':'2019-08-15 11:20:00','event_type':'transaction'}
{'job_no':'1','begin_artifact_time':'2019-08-15 11:20:01','event_type':'upload'}
{'job_no':'1','end_artifact_time':'2019-08-15 11:30:00','event_type':'upload'}
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;I need data table output like:&lt;BR /&gt;
&lt;STRONG&gt;Job# 1 staging 10 mins  transaction 10 mins upload 10 mins total 30 mins&lt;/STRONG&gt;&lt;/P&gt;

&lt;P&gt;Each line is coming as a event in Splunk. &lt;BR /&gt;
I know we have to use coalesce and streamstats, but I am new to splunk not able to figure out how to get to this level. &lt;/P&gt;

&lt;P&gt;Thanks in advance.&lt;/P&gt;</description>
      <pubDate>Thu, 15 Aug 2019 22:05:44 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/How-to-extract-two-values-from-two-same-fields-in-two-events-and/m-p/448538#M77964</guid>
      <dc:creator>vanakkam777</dc:creator>
      <dc:date>2019-08-15T22:05:44Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract two values from two same fields in two events and then find the difference in timestamp</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/How-to-extract-two-values-from-two-same-fields-in-two-events-and/m-p/448539#M77965</link>
      <description>&lt;P&gt;Try this run anywhere search&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| makeresults 
| eval data="{'job_no':'1','begin_build_time':'2019-08-15 11:00:00','event_type':'staging'} | {'job_no':'1','end_build_time':'2019-08-15 11:10:00','event_type':'staging'}" 
| makemv data delim="|" 
| mvexpand data 
| table data 
| rex field="data" "'job_no':'(?&amp;lt;job_no&amp;gt;[^\']+)','(begin_build_time':'(?&amp;lt;begin_build_time&amp;gt;[^\']+)|end_build_time':'(?&amp;lt;end_build_time&amp;gt;[^\']+))','event_type':'(?&amp;lt;type&amp;gt;[^\']+)'"| eval begin_build_time=strptime(begin_build_time,"%Y-%m-%d %H:%M:%S"),end_build_time=strptime(end_build_time,"%Y-%m-%d %H:%M:%S") 
| stats values(begin_build_time) as begin_build_time values(end_build_time) as end_build_time by type job_no
| eval time_diff_in_min=round((end_build_time-begin_build_time)/60)
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;In your env, you should try&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=&amp;lt;your_index&amp;gt;
| rex field=_raw "'job_no':'(?&amp;lt;job_no&amp;gt;[^\']+)','(begin_build_time':'(?&amp;lt;begin_build_time&amp;gt;[^\']+)|end_build_time':'(?&amp;lt;end_build_time&amp;gt;[^\']+))','event_type':'(?&amp;lt;type&amp;gt;[^\']+)'"| eval begin_build_time=strptime(begin_build_time,"%Y-%m-%d %H:%M:%S"),end_build_time=strptime(end_build_time,"%Y-%m-%d %H:%M:%S") 
| stats values(begin_build_time) as begin_build_time values(end_build_time) as end_build_time by type job_no
| eval time_diff_in_min=round((end_build_time-begin_build_time)/60)
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 15 Aug 2019 23:22:36 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/How-to-extract-two-values-from-two-same-fields-in-two-events-and/m-p/448539#M77965</guid>
      <dc:creator>mayurr98</dc:creator>
      <dc:date>2019-08-15T23:22:36Z</dc:date>
    </item>
  </channel>
</rss>

