<?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 search between two lines? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-to-search-between-two-lines/m-p/626950#M217882</link>
    <description>&lt;P&gt;Hello All,&lt;/P&gt;
&lt;P&gt;I have following lines in the log file -&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;Server8 runiyal 2023-01-12 09:48:41,880 INFO Plugin.DOCUMENT Bytes size from input stream : 2072823
server8 runiyal 2023-01-12 09:48:41,978 INFO Plugin.DOCUMENT File size after upload to temp folder: 2072823
server8 runiyal 2023-01-12 09:48:43,391 SUCCESS Plugin.DOCUMENT File size after notifying the docrepo : 2072823&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I want to -&lt;BR /&gt;1. Search for the DocID in the end &amp;lt;2072823&amp;gt;; It should have SUCCESS written in line. (Line3)&lt;BR /&gt;2. It should then look at the above line with string "from input stream" for the same DocID (Line 1)&lt;BR /&gt;3. Reduce the timestamp from SUCCESS line (3) to the timestamp in line with the text "from input stream" (Line 1) - Result will be in seconds&lt;BR /&gt;4. Result should be in two columns: "DocID" and "Time Taken" (4)&lt;/P&gt;
&lt;P&gt;Will appreciate your inputs on how this can be achieved. Thanks!&lt;/P&gt;</description>
    <pubDate>Thu, 12 Jan 2023 20:39:01 GMT</pubDate>
    <dc:creator>runiyal</dc:creator>
    <dc:date>2023-01-12T20:39:01Z</dc:date>
    <item>
      <title>How to search between two lines?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-search-between-two-lines/m-p/626950#M217882</link>
      <description>&lt;P&gt;Hello All,&lt;/P&gt;
&lt;P&gt;I have following lines in the log file -&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;Server8 runiyal 2023-01-12 09:48:41,880 INFO Plugin.DOCUMENT Bytes size from input stream : 2072823
server8 runiyal 2023-01-12 09:48:41,978 INFO Plugin.DOCUMENT File size after upload to temp folder: 2072823
server8 runiyal 2023-01-12 09:48:43,391 SUCCESS Plugin.DOCUMENT File size after notifying the docrepo : 2072823&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I want to -&lt;BR /&gt;1. Search for the DocID in the end &amp;lt;2072823&amp;gt;; It should have SUCCESS written in line. (Line3)&lt;BR /&gt;2. It should then look at the above line with string "from input stream" for the same DocID (Line 1)&lt;BR /&gt;3. Reduce the timestamp from SUCCESS line (3) to the timestamp in line with the text "from input stream" (Line 1) - Result will be in seconds&lt;BR /&gt;4. Result should be in two columns: "DocID" and "Time Taken" (4)&lt;/P&gt;
&lt;P&gt;Will appreciate your inputs on how this can be achieved. Thanks!&lt;/P&gt;</description>
      <pubDate>Thu, 12 Jan 2023 20:39:01 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-search-between-two-lines/m-p/626950#M217882</guid>
      <dc:creator>runiyal</dc:creator>
      <dc:date>2023-01-12T20:39:01Z</dc:date>
    </item>
    <item>
      <title>Re: Searching between two lines</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-search-between-two-lines/m-p/626954#M217884</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/138387"&gt;@runiyal&lt;/a&gt;,&lt;/P&gt;&lt;P&gt;I suppose that you already extracted the DocID field, otherwise you have to add a rex command before the stats command.&lt;/P&gt;&lt;P&gt;you could use the transaction command&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;index=your_index 1. (SUCCESS OR "from input stream" OR "from input stream")
| transaction DocID
| rename duration AS "Time Taken"
| table DocID "Time Taken"&lt;/LI-CODE&gt;&lt;P&gt;that's very slow, so try this different approach:&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;index=your_index 1. (SUCCESS OR "from input stream" OR "from input stream")
| stats 
   earliest(_time) AS earliest
   latest(_time) AS latest
   BY DocID
| eval Time_Take=latest-earliest
| table DocID Time_Taken
| rename Time_Taken AS "Time Taken"&lt;/LI-CODE&gt;&lt;P&gt;Ciao.&lt;/P&gt;&lt;P&gt;Giuseppe&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 12 Jan 2023 16:45:45 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-search-between-two-lines/m-p/626954#M217884</guid>
      <dc:creator>gcusello</dc:creator>
      <dc:date>2023-01-12T16:45:45Z</dc:date>
    </item>
    <item>
      <title>Re: Searching between two lines</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-search-between-two-lines/m-p/626967#M217888</link>
      <description>&lt;P&gt;&lt;SPAN&gt;Thanks&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;Giuseppe.. I have to extract the docID field too.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 12 Jan 2023 18:51:38 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-search-between-two-lines/m-p/626967#M217888</guid>
      <dc:creator>runiyal</dc:creator>
      <dc:date>2023-01-12T18:51:38Z</dc:date>
    </item>
    <item>
      <title>Re: Searching between two lines</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-search-between-two-lines/m-p/627026#M217919</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/138387"&gt;@runiyal&lt;/a&gt;,&lt;/P&gt;&lt;P&gt;in this case. you have to add a regex extraction to your search:&lt;/P&gt;&lt;P&gt;with transaction:&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;index=your_index 1. (SUCCESS OR "from input stream" OR "from input stream")
| rex "(?&amp;lt;DocID&amp;gt;\d+)$"
| transaction DocID
| rename duration AS "Time Taken"
| table DocID "Time Taken"&lt;/LI-CODE&gt;&lt;P&gt;or with stats (better):&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;index=your_index 1. (SUCCESS OR "from input stream" OR "from input stream")
| rex "(?&amp;lt;DocID&amp;gt;\d+)$"
| stats 
   earliest(_time) AS earliest
   latest(_time) AS latest
   BY DocID
| eval Time_Take=latest-earliest
| table DocID Time_Taken
| rename Time_Taken AS "Time Taken"&lt;/LI-CODE&gt;&lt;P&gt;You can test the regex at&amp;nbsp;&lt;A href="https://regex101.com/r/TgQtHA/1" target="_blank"&gt;https://regex101.com/r/TgQtHA/1&lt;/A&gt;&lt;/P&gt;&lt;P&gt;Ciao.&lt;/P&gt;&lt;P&gt;Giuseppe&lt;/P&gt;</description>
      <pubDate>Fri, 13 Jan 2023 07:09:24 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-search-between-two-lines/m-p/627026#M217919</guid>
      <dc:creator>gcusello</dc:creator>
      <dc:date>2023-01-13T07:09:24Z</dc:date>
    </item>
  </channel>
</rss>

