<?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 do you search for the nearest file within 7 days ago of another file? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-do-you-search-for-the-nearest-file-within-7-days-ago-of/m-p/449231#M127220</link>
    <description>&lt;P&gt;Hi,&lt;/P&gt;

&lt;P&gt;Can you try it like this&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt; your search here
 | rex field=source "/[^/]+(?&amp;lt;date&amp;gt;\d{8})[^/]+$"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;It will extract the date out of your file_name&lt;BR /&gt;
then you can compare&lt;/P&gt;</description>
    <pubDate>Tue, 30 Oct 2018 10:48:12 GMT</pubDate>
    <dc:creator>iamarkaprabha</dc:creator>
    <dc:date>2018-10-30T10:48:12Z</dc:date>
    <item>
      <title>How do you search for the nearest file within 7 days ago of another file?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-you-search-for-the-nearest-file-within-7-days-ago-of/m-p/449228#M127217</link>
      <description>&lt;P&gt;Hello everyone,&lt;/P&gt;

&lt;P&gt;I'd like to create a bottleneck graph. &lt;/P&gt;

&lt;P&gt;Basically, I'd like to use two files. One of the files is a recent file and the other is 7 days before the recent file. &lt;/P&gt;

&lt;P&gt;e.g.&lt;/P&gt;

&lt;P&gt;If I have 3files as below in one index, &lt;BR /&gt;
1. 20181022.csv&lt;BR /&gt;
2. 20181025.csv&lt;BR /&gt;
3. 20181030.csv&lt;/P&gt;

&lt;OL&gt;
&lt;LI&gt;&lt;P&gt;When I display the data on 2018/10/30...&lt;BR /&gt;
2018/10/23 is 7 days before 2018/10/30. But, there isn't a file for that day. In that case, I'd like to use the file that is the nearest to 2018/10/23 within 7 days. So, I'd like to use the data of &lt;STRONG&gt;20181030.csv&lt;/STRONG&gt; file and &lt;STRONG&gt;20181025.csv.&lt;/STRONG&gt;&lt;/P&gt;&lt;/LI&gt;
&lt;LI&gt;&lt;P&gt;When I display the data on 2018/10/25&lt;BR /&gt;
It's the same way as above. 2018/10/18 is 7 days before 2018/10/25. But, there is no data for that date.&lt;BR /&gt;
So, I'd like to use the file &lt;STRONG&gt;20181022.csv.&lt;/STRONG&gt; This file is the nearest to 2018/10/18 within 7 days.&lt;/P&gt;&lt;/LI&gt;
&lt;/OL&gt;

&lt;P&gt;How can I search for the file that is the nearest within 7 days before the recent file?&lt;/P&gt;

&lt;P&gt;The nearest file has to be within 7days.&lt;/P&gt;

&lt;P&gt;Please let me know how to do. &lt;/P&gt;

&lt;P&gt;I need search query. &lt;/P&gt;

&lt;P&gt;Thank you in advance. &lt;/P&gt;</description>
      <pubDate>Tue, 30 Oct 2018 08:24:35 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-you-search-for-the-nearest-file-within-7-days-ago-of/m-p/449228#M127217</guid>
      <dc:creator>jenny_life</dc:creator>
      <dc:date>2018-10-30T08:24:35Z</dc:date>
    </item>
    <item>
      <title>Re: How do you search for the nearest file within 7 days ago of another file?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-you-search-for-the-nearest-file-within-7-days-ago-of/m-p/449229#M127218</link>
      <description>&lt;P&gt;Hi ,&lt;/P&gt;

&lt;P&gt;This happened maybe the file got indexed at that particular day,&lt;BR /&gt;
You can add tz=UTC in props.conf for this one&lt;/P&gt;

&lt;P&gt;It will be like this&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;[source::\\\\SERVERNAME\\prod-iislogs\...\...\\C*.log]
TZ = GMT
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 30 Oct 2018 08:29:15 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-you-search-for-the-nearest-file-within-7-days-ago-of/m-p/449229#M127218</guid>
      <dc:creator>iamarkaprabha</dc:creator>
      <dc:date>2018-10-30T08:29:15Z</dc:date>
    </item>
    <item>
      <title>Re: How do you search for the nearest file within 7 days ago of another file?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-you-search-for-the-nearest-file-within-7-days-ago-of/m-p/449230#M127219</link>
      <description>&lt;P&gt;Thank you for your answer.&lt;BR /&gt;
But, those three files are already in the index.&lt;BR /&gt;
(I imported those files to index .)&lt;BR /&gt;
I'd like to know how to search the nearest file within 7days .&lt;BR /&gt;
(What within 7days mean is , It depends on the date.&lt;BR /&gt;
for example, &lt;BR /&gt;
If standard date is 2018/10/30, 'within 7days' is from 2018/10/23 to 2018/10/30. &lt;BR /&gt;
in that case , what I'd like to find the file is '20181025.csv'.)&lt;/P&gt;

&lt;P&gt;↓ I need a search query like this style.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index="bottleneck"  source="*bottleneck*"
| eval date = 'occurrenceDate'
| eval before5Days = strftime(relative_time(strptime(date, "%Y/%m/%d"), "-7d@d"),"%Y/%m/%d")
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 30 Oct 2018 08:48:16 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-you-search-for-the-nearest-file-within-7-days-ago-of/m-p/449230#M127219</guid>
      <dc:creator>jenny_life</dc:creator>
      <dc:date>2018-10-30T08:48:16Z</dc:date>
    </item>
    <item>
      <title>Re: How do you search for the nearest file within 7 days ago of another file?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-you-search-for-the-nearest-file-within-7-days-ago-of/m-p/449231#M127220</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;

&lt;P&gt;Can you try it like this&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt; your search here
 | rex field=source "/[^/]+(?&amp;lt;date&amp;gt;\d{8})[^/]+$"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;It will extract the date out of your file_name&lt;BR /&gt;
then you can compare&lt;/P&gt;</description>
      <pubDate>Tue, 30 Oct 2018 10:48:12 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-you-search-for-the-nearest-file-within-7-days-ago-of/m-p/449231#M127220</guid>
      <dc:creator>iamarkaprabha</dc:creator>
      <dc:date>2018-10-30T10:48:12Z</dc:date>
    </item>
    <item>
      <title>Re: How do you search for the nearest file within 7 days ago of another file?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-you-search-for-the-nearest-file-within-7-days-ago-of/m-p/449232#M127221</link>
      <description>&lt;P&gt;Thank you for your attention.&lt;/P&gt;

&lt;P&gt;I'm sorry that i didn't explain well..&lt;BR /&gt;
what I exactly want is,,&lt;BR /&gt;
I'd like to know how to compare,,&lt;BR /&gt;
I can extract date from source file name.&lt;BR /&gt;
after that, how should i do?&lt;/P&gt;

&lt;P&gt;please refer to my query.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;   index="bottleneck"  source="*.csv*"
   | eval temp = split('source',".")
   | eval date = mvindex(temp,0)
   | sort date
   | eval before7Days = strftime(relative_time(strptime(date, "%Y%m%d"), "-7d@d"),"%Y%m%d")
   | dedup date
   | table date before7Days
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;If i execute this query , the result is as below.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;date      before7Days
20181022    20181015
20181025    20181018
20181030    20181023
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;but, Actually what i need is as below.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;date      before7Days
20181022    20181015 (There is no file(20181015) in the index. So it doesn't care whatever)
20181025    20181022 (actual 7 days before = 20181018, but the nearest file = 20181022.)
20181030    20181025  (actual 7days before is 20181023, but there is no file so I'd like to use the 20181025.csv That is the nearest file to 2018/10/23. (between 2018/10/30 and 2018/10/23))
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;So i'd like know the search or comparison query in order to display the result as above .&lt;/P&gt;</description>
      <pubDate>Tue, 30 Oct 2018 11:22:13 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-you-search-for-the-nearest-file-within-7-days-ago-of/m-p/449232#M127221</guid>
      <dc:creator>jenny_life</dc:creator>
      <dc:date>2018-10-30T11:22:13Z</dc:date>
    </item>
  </channel>
</rss>

