<?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 to extract and find the difference in time between two fields using regex? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-to-extract-and-find-the-difference-in-time-between-two/m-p/342171#M101387</link>
    <description>&lt;P&gt;hey try this run anywhere search &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| makeresults 
|  eval _raw="Worker#108 [SWAPScheduler-INDIA] - [2018-01-31 04:30:04,340] - DEBUG - AppLogger: SWAPScheduler.executeInternal entry"
 | append
    [ | makeresults 
    |  eval _raw="Worker#108 [SWAPScheduler-INDIA] - [2018-01-31 04:30:04,340] - DEBUG - AppLogger: SWAPScheduler.executeInternal exit"] 
| rex field=_raw "\s-\s\[((?&amp;lt;entry_time&amp;gt;[^\]]+).*entry|(?&amp;lt;exit_time&amp;gt;[^\]]+).*exit)"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;in your environment, you should write&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;&amp;lt;your_base_search&amp;gt; | rex field=_raw "\s-\s\[((?&amp;lt;entry_time&amp;gt;[^\]]+).*entry|(?&amp;lt;exit_time&amp;gt;[^\]]+).*exit)"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;let me know if this helps!&lt;/P&gt;</description>
    <pubDate>Thu, 01 Feb 2018 06:18:04 GMT</pubDate>
    <dc:creator>mayurr98</dc:creator>
    <dc:date>2018-02-01T06:18:04Z</dc:date>
    <item>
      <title>How to extract and find the difference in time between two fields using regex?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-extract-and-find-the-difference-in-time-between-two/m-p/342168#M101384</link>
      <description>&lt;P&gt;Hi , &lt;/P&gt;

&lt;P&gt;I have 2 events like below and I need to find the difference in time between 2 events. There may be a lot of other events between them. &lt;BR /&gt;
I'm trying to write a regular expression to extract the time in [] brackets and create as an &lt;CODE&gt;EntryTIME&lt;/CODE&gt; and &lt;CODE&gt;EXITTIME&lt;/CODE&gt; fields. &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;Event 1: Worker#108 [SWAPScheduler-INDIA] - [2018-01-31 04:30:04,340] - DEBUG - AppLogger: SWAPScheduler.executeInternal entry

Event 2: Worker#108 [SWAPScheduler-INDIA] - [2018-01-31 04:30:04,340] - DEBUG - AppLogger: SWAPScheduler.executeInternal exit 
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Please help me in creating regex to extract this in Splunk. I tried field extractor but it's allowing only 1 string to add as a required text. If I do this I can't have 2 fields to get entry time and exit time. &lt;/P&gt;</description>
      <pubDate>Wed, 31 Jan 2018 23:30:45 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-extract-and-find-the-difference-in-time-between-two/m-p/342168#M101384</guid>
      <dc:creator>rrkollip</dc:creator>
      <dc:date>2018-01-31T23:30:45Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract and find the difference in time between two fields using regex?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-extract-and-find-the-difference-in-time-between-two/m-p/342169#M101385</link>
      <description>&lt;P&gt;Try this - You can run this as is copying and pasting it in your search.  - you can tweak it a little bit to fit your needs:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| stats count | eval data = "Event 1: Worker#108 [SWAPScheduler-INDIA] - [2018-01-31 04:30:04,340] - DEBUG - AppLogger: SWAPScheduler.executeInternal entry;Event 1: Worker#115 [SWAPScheduler-INDIA] - [2018-01-31 04:30:09,340] - DEBUG - AppLogger: SWAPScheduler.executeInternal entry;
  Event 2: Worker#115 [SWAPScheduler-INDIA] - [2018-01-31 04:30:29,340] - DEBUG - AppLogger: SWAPScheduler.executeInternal exit;
 Event 2: Worker#108 [SWAPScheduler-INDIA] - [2018-01-31 04:30:34,340] - DEBUG - AppLogger: SWAPScheduler.executeInternal exit" | makemv delim=";" data 
 | mvexpand data | rename data as _raw  | rex field=_raw ".*Worker\#(?&amp;lt;worker_id&amp;gt;[\d+]*).*\-\s(\[(?&amp;lt;entry_time&amp;gt;[^\]]*).*entry|\[(?&amp;lt;exit_time&amp;gt;[^\]]*).*exit)"
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 01 Feb 2018 00:59:29 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-extract-and-find-the-difference-in-time-between-two/m-p/342169#M101385</guid>
      <dc:creator>nabeel652</dc:creator>
      <dc:date>2018-02-01T00:59:29Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract and find the difference in time between two fields using regex?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-extract-and-find-the-difference-in-time-between-two/m-p/342170#M101386</link>
      <description>&lt;P&gt;are you expecting something like this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;... | rex field=_raw "(.*\]\s\-\s\[(?&amp;lt;entry_time&amp;gt;[^\,]*).*executeInternal\sentry)|(.*\]\s\-\s\[(?&amp;lt;exit_time&amp;gt;[^\,]*).*executeInternal\sexit)"
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 01 Feb 2018 04:40:22 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-extract-and-find-the-difference-in-time-between-two/m-p/342170#M101386</guid>
      <dc:creator>493669</dc:creator>
      <dc:date>2018-02-01T04:40:22Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract and find the difference in time between two fields using regex?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-extract-and-find-the-difference-in-time-between-two/m-p/342171#M101387</link>
      <description>&lt;P&gt;hey try this run anywhere search &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| makeresults 
|  eval _raw="Worker#108 [SWAPScheduler-INDIA] - [2018-01-31 04:30:04,340] - DEBUG - AppLogger: SWAPScheduler.executeInternal entry"
 | append
    [ | makeresults 
    |  eval _raw="Worker#108 [SWAPScheduler-INDIA] - [2018-01-31 04:30:04,340] - DEBUG - AppLogger: SWAPScheduler.executeInternal exit"] 
| rex field=_raw "\s-\s\[((?&amp;lt;entry_time&amp;gt;[^\]]+).*entry|(?&amp;lt;exit_time&amp;gt;[^\]]+).*exit)"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;in your environment, you should write&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;&amp;lt;your_base_search&amp;gt; | rex field=_raw "\s-\s\[((?&amp;lt;entry_time&amp;gt;[^\]]+).*entry|(?&amp;lt;exit_time&amp;gt;[^\]]+).*exit)"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;let me know if this helps!&lt;/P&gt;</description>
      <pubDate>Thu, 01 Feb 2018 06:18:04 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-extract-and-find-the-difference-in-time-between-two/m-p/342171#M101387</guid>
      <dc:creator>mayurr98</dc:creator>
      <dc:date>2018-02-01T06:18:04Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract and find the difference in time between two fields using regex?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-extract-and-find-the-difference-in-time-between-two/m-p/342172#M101388</link>
      <description>&lt;P&gt;Please check the updated answer&lt;/P&gt;</description>
      <pubDate>Thu, 01 Feb 2018 06:32:06 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-extract-and-find-the-difference-in-time-between-two/m-p/342172#M101388</guid>
      <dc:creator>nabeel652</dc:creator>
      <dc:date>2018-02-01T06:32:06Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract and find the difference in time between two fields using regex?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-extract-and-find-the-difference-in-time-between-two/m-p/342173#M101389</link>
      <description>&lt;P&gt;This worked to get the entry &amp;amp; exit time. When I run query like below to calculate the difference, none of the strptime and strftime functions works with fields entry_time and exit_time. &lt;/P&gt;

&lt;P&gt;My base search | rex field=_raw ".&lt;EM&gt;Worker#(?[\d+]&lt;/EM&gt;).&lt;EM&gt;-\s([(?[^]]&lt;/EM&gt;).&lt;EM&gt;entry|[(?[^]]&lt;/EM&gt;).*exit)" | eval entry=strptime(entry_time,"%d/%m/%Y-%H:%M:%S") | eval exit=strptime(exit_time,"%d/%m/%Y-%H:%M:%S") | eval diff = exit-entry&lt;/P&gt;

&lt;P&gt;Does strptime and strftime functions works with the fields extracted from regex? &lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2020 17:58:04 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-extract-and-find-the-difference-in-time-between-two/m-p/342173#M101389</guid>
      <dc:creator>rrkollip</dc:creator>
      <dc:date>2020-09-29T17:58:04Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract and find the difference in time between two fields using regex?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-extract-and-find-the-difference-in-time-between-two/m-p/342174#M101390</link>
      <description>&lt;P&gt;Well for strptime you'll have to provide the timeformat string that matches the date/time in entry_time and exit_time. So you need to do:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| eval exit = strptime(exit_time,"%Y-%m-%d %H:%M:%S")
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;However by doing |eval diff = exit - entry you'll not get any useful results because entry_time corresponding to every exit_time (and vise versa) are NULL. &lt;/P&gt;

&lt;P&gt;In order to get time difference between entry and exit you'll have to use the transaction command that I worked out earlier. &lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2020 18:00:50 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-extract-and-find-the-difference-in-time-between-two/m-p/342174#M101390</guid>
      <dc:creator>nabeel652</dc:creator>
      <dc:date>2020-09-29T18:00:50Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract and find the difference in time between two fields using regex?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-extract-and-find-the-difference-in-time-between-two/m-p/342175#M101391</link>
      <description>&lt;P&gt;If you still want duration through same query use this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;    | stats count | eval data = "Event 1: Worker#108 [SWAPScheduler-INDIA] - [2018-01-31 04:30:04,340] - DEBUG - AppLogger: SWAPScheduler.executeInternal entry;Event 1: Worker#115 [SWAPScheduler-INDIA] - [2018-01-31 04:30:09,340] - DEBUG - AppLogger: SWAPScheduler.executeInternal entry;
   Event 2: Worker#115 [SWAPScheduler-INDIA] - [2018-01-31 04:30:29,340] - DEBUG - AppLogger: SWAPScheduler.executeInternal exit;
  Event 2: Worker#108 [SWAPScheduler-INDIA] - [2018-01-31 04:30:34,340] - DEBUG - AppLogger: SWAPScheduler.executeInternal exit" | makemv delim=";" data 
  | mvexpand data | rename data as _raw | rex field=_raw ".*Worker\#(?[\d+]*).*\-\s(\[(?[^\]]*).*entry|\[(?[^\]]*).*exit)"  | stats first(entry_time) as entry last(exit_time) as exit by worker_id | eval entry = strptime(entry,"%Y-%m-%d %H:%M:%S") | eval exit = strptime(exit,"%Y-%m-%d %H:%M:%S") | eval diff = round(exit -entry,0)
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 07 Feb 2018 01:37:45 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-extract-and-find-the-difference-in-time-between-two/m-p/342175#M101391</guid>
      <dc:creator>nabeel652</dc:creator>
      <dc:date>2018-02-07T01:37:45Z</dc:date>
    </item>
  </channel>
</rss>

