<?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 find the time period of successive table lines? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-to-find-the-time-period-of-successive-table-lines/m-p/275105#M82984</link>
    <description>&lt;P&gt;What do you mean?&lt;/P&gt;

&lt;P&gt;This is the csv I'm using to replicate your use case:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;_time,src_host, src_ip
06/19/16,A,10.10.10.10
06/20/16,A,9.9.9.9
06/21/16,A,9.9.9.9
06/22/16,A,10.10.10.10
06/24/16,A,10.10.10.10
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;This is the query:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| inputcsv mycsv.csv
| eval _time = strptime(_time, "%m/%d/%y")
| sort limit=0 _time, src_host, src_ip
| streamstats window=2 first(_time) as start_time by src_host, src_ip
| sort limit=0 - _time, + src_host, + src_ip
| streamstats window=2 first(_time) as end_time by src_host, src_ip
| eval start_time = mvjoin(strftime(start_time, "%m/%d/%y"), " - ")
| eval end_time = mvjoin(strftime(end_time, "%m/%d/%y"), " - ")
| sort limit=0 _time, src_host, src_ip
| eval duration = if(start_time == end_time, start_time, start_time . " - " . end_time)
| stats values(duration) as duration by src_host, src_ip
| eval duration = mvjoin(duration, ", ")
| sort limit=0 src_host, src_ip
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;And this is the output:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;src_host, src_ip, duration
A, 9.9.9.9, 06/20/16 - 06/21/16
A, 10.10.10.10, 06/19/16, 06/22/16 - 06/24/16 
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Isn't that what you are looking for according to your sample?&lt;/P&gt;</description>
    <pubDate>Wed, 20 Jul 2016 12:26:51 GMT</pubDate>
    <dc:creator>javiergn</dc:creator>
    <dc:date>2016-07-20T12:26:51Z</dc:date>
    <item>
      <title>How to find the time period of successive table lines?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-find-the-time-period-of-successive-table-lines/m-p/275100#M82979</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;

&lt;P&gt;I have a base search which output me something like this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;_time            src_host             src_ip
06/19/16      A                         10.10.10.10
06/20/16      A                         9.9.9.9
06/21/16      A                         9.9.9.9
06/22/16      A                         10.10.10.10
06/24/16      A                         10.10.10.10
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;And I'd like to have a summary of this data because I have hundred of lines.&lt;BR /&gt;
Is it possible to get this output:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;duration                                src_host                        src_ip
06/19/16,06/22/16-06/24/16              A                           10.10.10.10
06/20/16-06/21/16                       A                           9.9.9.9
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Edit: Please note that successive values are surrounding with a dash "-" and non-successive values are separated by a comma ",".&lt;/P&gt;

&lt;P&gt;Thank you !&lt;/P&gt;</description>
      <pubDate>Wed, 20 Jul 2016 08:46:55 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-find-the-time-period-of-successive-table-lines/m-p/275100#M82979</guid>
      <dc:creator>ctaf</dc:creator>
      <dc:date>2016-07-20T08:46:55Z</dc:date>
    </item>
    <item>
      <title>Re: How to find the time period of successive table lines?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-find-the-time-period-of-successive-table-lines/m-p/275101#M82980</link>
      <description>&lt;P&gt;Try this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;your base search
| stats values(_time) as duration by src_host, src_ip
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;If you still want duration values separated by commas then you can do it this way:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;your base search
| stats values(_time) as duration by src_host, src_ip
| eval duration = mvjoin(duration, ",")
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Hope that helps,&lt;BR /&gt;
J&lt;/P&gt;

&lt;P&gt;EDIT (other options as suggested below):&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;your base search
| eval _time = strptime(_time, "%m/%d/%y")
| sort limit=0 _time, src_host, src_ip
| streamstats window=2 first(_time) as start_time by src_host, src_ip
| sort limit=0 - _time, + src_host, + src_ip
| streamstats window=2 first(_time) as end_time by src_host, src_ip
| eval start_time = mvjoin(strftime(start_time, "%m/%d/%y"), " - ")
| eval end_time = mvjoin(strftime(end_time, "%m/%d/%y"), " - ")
| sort limit=0 _time, src_host, src_ip
| eval duration = if(start_time == end_time, start_time, start_time . " - " . end_time)
| stats values(duration) as duration by src_host, src_ip
| eval duration = mvjoin(duration, ", ")
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;HR /&gt;

&lt;PRE&gt;&lt;CODE&gt;your base search
 | eval _time = strptime(_time, "%m/%d/%y")
 | sort limit=0 _time, src_host, src_ip
 | streamstats window=2 reset_on_change=t first(_time) as start_time, range(_time) as dur by src_host, src_ip
 | eval dur = round(dur/86400)
 | eval start_time = if(dur&amp;gt;1, _time, start_time)
 | streamstats reset_on_change=t first(start_time) as start_time by dur, src_host, src_ip
 | eventstats last(_time) as end_time by start_time, src_host, src_ip
 | eval start_time = mvjoin(strftime(start_time, "%m/%d/%y"), " - ")
 | eval end_time = mvjoin(strftime(end_time, "%m/%d/%y"), " - ")
 | eval duration = if(start_time == end_time, start_time, start_time . " - " . end_time)
 | stats values(duration) as duration by src_host, src_ip
 | eval duration = mvjoin(duration, ", ")
 | sort limit=0 src_host, src_ip
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 20 Jul 2016 08:52:09 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-find-the-time-period-of-successive-table-lines/m-p/275101#M82980</guid>
      <dc:creator>javiergn</dc:creator>
      <dc:date>2016-07-20T08:52:09Z</dc:date>
    </item>
    <item>
      <title>Re: How to find the time period of successive table lines?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-find-the-time-period-of-successive-table-lines/m-p/275102#M82981</link>
      <description>&lt;P&gt;thank you for your answer javiergn. But with your solution, I am grouping all the _time values on a single row without order. As you can see in my example, I am surrounding successif values with "-" and the rest is separated by ",". It gives me only the period where the IP was actually leased to the host.&lt;/P&gt;</description>
      <pubDate>Wed, 20 Jul 2016 08:59:39 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-find-the-time-period-of-successive-table-lines/m-p/275102#M82981</guid>
      <dc:creator>ctaf</dc:creator>
      <dc:date>2016-07-20T08:59:39Z</dc:date>
    </item>
    <item>
      <title>Re: How to find the time period of successive table lines?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-find-the-time-period-of-successive-table-lines/m-p/275103#M82982</link>
      <description>&lt;P&gt;Hmm, that's a bit more complicated but doable I think.&lt;/P&gt;

&lt;P&gt;See if the following help:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;your base search
| eval _time = strptime(_time, "%m/%d/%y")
| sort limit=0 _time, src_host, src_ip
| streamstats window=2 first(_time) as start_time by src_host, src_ip
| sort limit=0 - _time, + src_host, + src_ip
| streamstats window=2 first(_time) as end_time by src_host, src_ip
| eval start_time = mvjoin(strftime(start_time, "%m/%d/%y"), " - ")
| eval end_time = mvjoin(strftime(end_time, "%m/%d/%y"), " - ")
| sort limit=0 _time, src_host, src_ip
| eval duration = if(start_time == end_time, start_time, start_time . " - " . end_time)
| stats values(duration) as duration by src_host, src_ip
| eval duration = mvjoin(duration, ", ")
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 20 Jul 2016 11:16:56 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-find-the-time-period-of-successive-table-lines/m-p/275103#M82982</guid>
      <dc:creator>javiergn</dc:creator>
      <dc:date>2016-07-20T11:16:56Z</dc:date>
    </item>
    <item>
      <title>Re: How to find the time period of successive table lines?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-find-the-time-period-of-successive-table-lines/m-p/275104#M82983</link>
      <description>&lt;P&gt;Yes it is indeed more complicated. I am not sure to understand how streamstats works but unfortunately, it is not summed up enough, because the ouput is :&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt; 02/16/16, 02/16/16, 02/16/16 - 02/17/16, 02/17/16 - 02/18/16.....
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Following days are not summed up.&lt;/P&gt;</description>
      <pubDate>Wed, 20 Jul 2016 12:16:55 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-find-the-time-period-of-successive-table-lines/m-p/275104#M82983</guid>
      <dc:creator>ctaf</dc:creator>
      <dc:date>2016-07-20T12:16:55Z</dc:date>
    </item>
    <item>
      <title>Re: How to find the time period of successive table lines?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-find-the-time-period-of-successive-table-lines/m-p/275105#M82984</link>
      <description>&lt;P&gt;What do you mean?&lt;/P&gt;

&lt;P&gt;This is the csv I'm using to replicate your use case:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;_time,src_host, src_ip
06/19/16,A,10.10.10.10
06/20/16,A,9.9.9.9
06/21/16,A,9.9.9.9
06/22/16,A,10.10.10.10
06/24/16,A,10.10.10.10
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;This is the query:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| inputcsv mycsv.csv
| eval _time = strptime(_time, "%m/%d/%y")
| sort limit=0 _time, src_host, src_ip
| streamstats window=2 first(_time) as start_time by src_host, src_ip
| sort limit=0 - _time, + src_host, + src_ip
| streamstats window=2 first(_time) as end_time by src_host, src_ip
| eval start_time = mvjoin(strftime(start_time, "%m/%d/%y"), " - ")
| eval end_time = mvjoin(strftime(end_time, "%m/%d/%y"), " - ")
| sort limit=0 _time, src_host, src_ip
| eval duration = if(start_time == end_time, start_time, start_time . " - " . end_time)
| stats values(duration) as duration by src_host, src_ip
| eval duration = mvjoin(duration, ", ")
| sort limit=0 src_host, src_ip
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;And this is the output:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;src_host, src_ip, duration
A, 9.9.9.9, 06/20/16 - 06/21/16
A, 10.10.10.10, 06/19/16, 06/22/16 - 06/24/16 
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Isn't that what you are looking for according to your sample?&lt;/P&gt;</description>
      <pubDate>Wed, 20 Jul 2016 12:26:51 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-find-the-time-period-of-successive-table-lines/m-p/275105#M82984</guid>
      <dc:creator>javiergn</dc:creator>
      <dc:date>2016-07-20T12:26:51Z</dc:date>
    </item>
    <item>
      <title>Re: How to find the time period of successive table lines?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-find-the-time-period-of-successive-table-lines/m-p/275106#M82985</link>
      <description>&lt;P&gt;Actually, in real, the data contains more lines. Like this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;_time,src_host, src_ip
 06/19/16,A,10.10.10.10
 06/20/16,A,9.9.9.9
 06/21/16,A,9.9.9.9
 06/22/16,A,10.10.10.10
 06/24/16,A,10.10.10.10
 06/25/16,A,10.10.10.10
 06/26/16,A,10.10.10.10
 06/28/16,A,10.10.10.10
 06/29/16,A,10.10.10.10
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 20 Jul 2016 12:32:33 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-find-the-time-period-of-successive-table-lines/m-p/275106#M82985</guid>
      <dc:creator>ctaf</dc:creator>
      <dc:date>2016-07-20T12:32:33Z</dc:date>
    </item>
    <item>
      <title>Re: How to find the time period of successive table lines?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-find-the-time-period-of-successive-table-lines/m-p/275107#M82986</link>
      <description>&lt;P&gt;so what would you expect out of this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;  06/22/16,A,10.10.10.10
  06/24/16,A,10.10.10.10
  06/25/16,A,10.10.10.10
  06/26/16,A,10.10.10.10
  06/28/16,A,10.10.10.10
  06/29/16,A,10.10.10.10
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;a) 06/22/16 - 06/29/16,A,10.10.10.10&lt;BR /&gt;
b) 06/22/16, 06/24/16 - 06/29/16,A,10.10.10.10&lt;BR /&gt;
?&lt;/P&gt;</description>
      <pubDate>Wed, 20 Jul 2016 12:36:52 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-find-the-time-period-of-successive-table-lines/m-p/275107#M82986</guid>
      <dc:creator>javiergn</dc:creator>
      <dc:date>2016-07-20T12:36:52Z</dc:date>
    </item>
    <item>
      <title>Re: How to find the time period of successive table lines?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-find-the-time-period-of-successive-table-lines/m-p/275108#M82987</link>
      <description>&lt;P&gt;c) &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;06/22/16, 06/24/16 - 06/26/16, 06/28/16 - 06/29/16         A           10.10.10.10
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 20 Jul 2016 12:42:15 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-find-the-time-period-of-successive-table-lines/m-p/275108#M82987</guid>
      <dc:creator>ctaf</dc:creator>
      <dc:date>2016-07-20T12:42:15Z</dc:date>
    </item>
    <item>
      <title>Re: How to find the time period of successive table lines?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-find-the-time-period-of-successive-table-lines/m-p/275109#M82988</link>
      <description>&lt;P&gt;OK, one more attempt:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;your base search
| eval _time = strptime(_time, "%m/%d/%y")
| sort limit=0 _time, src_host, src_ip
| streamstats window=2 reset_on_change=t first(_time) as start_time, range(_time) as dur by src_host, src_ip
| eval dur = round(dur/86400)
| eval start_time = if(dur&amp;gt;1, _time, start_time)
| streamstats reset_on_change=t first(start_time) as start_time by dur, src_host, src_ip
| eventstats last(_time) as end_time by start_time, src_host, src_ip
| eval start_time = mvjoin(strftime(start_time, "%m/%d/%y"), " - ")
| eval end_time = mvjoin(strftime(end_time, "%m/%d/%y"), " - ")
| eval duration = if(start_time == end_time, start_time, start_time . " - " . end_time)
| stats values(duration) as duration by src_host, src_ip
| eval duration = mvjoin(duration, ", ")
| sort limit=0 src_host, src_ip
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Output based on your sample above:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;src_host   src_ip   duration
--------------------------------------------------------
A   9.9.9.9   06/20/16 - 06/21/16
A   10.10.10.10   06/19/16, 06/22/16, 06/24/16 - 06/26/16, 06/28/16 - 06/29/16 
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 20 Jul 2016 15:00:02 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-find-the-time-period-of-successive-table-lines/m-p/275109#M82988</guid>
      <dc:creator>javiergn</dc:creator>
      <dc:date>2016-07-20T15:00:02Z</dc:date>
    </item>
    <item>
      <title>Re: How to find the time period of successive table lines?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-find-the-time-period-of-successive-table-lines/m-p/275110#M82989</link>
      <description>&lt;P&gt;Again, thank you for your help. But it is still strange because I have an output like this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;07/15/15 - 07/16/15, 07/20/15 - 07/24/15, 07/27/15 - 07/31/15, 08/03/15 - 08/07/15 ......
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;But in my base search output, I have a successive list of the same IP from 07/15/15 to 12/11/15&lt;/P&gt;

&lt;P&gt;If I apply your search only from 07/15/15 to 12/11/15, I get the right output. But with a larger scope, I get &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;07/15/15 - 07/16/15, 07/20/15 - 07/24/15, 07/27/15 - 07/31/15, 08/03/15 - 08/07/15 ......
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 20 Jul 2016 15:20:36 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-find-the-time-period-of-successive-table-lines/m-p/275110#M82989</guid>
      <dc:creator>ctaf</dc:creator>
      <dc:date>2016-07-20T15:20:36Z</dc:date>
    </item>
  </channel>
</rss>

