<?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: Export search results into YYYYMM.csv dynamically based on log date in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Export-search-results-into-YYYYMM-csv-dynamically-based-on-log/m-p/149175#M41703</link>
    <description>&lt;P&gt;Hi Henry,&lt;/P&gt;

&lt;P&gt;try this,&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;sourcetype=x,as_log ID | table _time ID mcn begin_action Desc _raw | outputcsv [ | stats count | eval filename=strftime(now(), "%Y%m") | return $filename]
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;The above query will help you to get the today's date. your can change the sub search based on your requirement like instead of now() you can use any date param.&lt;/P&gt;

&lt;P&gt;Cheersss!&lt;/P&gt;</description>
    <pubDate>Thu, 11 Dec 2014 04:22:46 GMT</pubDate>
    <dc:creator>vasanthmss</dc:creator>
    <dc:date>2014-12-11T04:22:46Z</dc:date>
    <item>
      <title>Export search results into YYYYMM.csv dynamically based on log date</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Export-search-results-into-YYYYMM-csv-dynamically-based-on-log/m-p/149173#M41701</link>
      <description>&lt;P&gt;As stated in subject line, i would like to split a huge log with past 12 months' log records and dynamically without hardcoding the dates and export search results into YYYYMM.csv accordingly based on their log date, how could i do that ? &lt;/P&gt;

&lt;P&gt;E.g. From my search command&lt;BR /&gt;
sourcetype=xmas_log ID begin.action date_month=January | table _time ID mcn begin_action Desc  _raw |outputcsv 201401.csv&lt;/P&gt;

&lt;P&gt;can i do something like:&lt;BR /&gt;
sourcetype=x,as_log ID begin.action date_month=$YYYYMM| table _time ID mcn begin_action Desc  _raw |outputcsv $YYYYMM.csv&lt;/P&gt;

&lt;P&gt;Thank you very much!&lt;/P&gt;</description>
      <pubDate>Mon, 28 Sep 2020 18:21:25 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Export-search-results-into-YYYYMM-csv-dynamically-based-on-log/m-p/149173#M41701</guid>
      <dc:creator>henry_ty_leung</dc:creator>
      <dc:date>2020-09-28T18:21:25Z</dc:date>
    </item>
    <item>
      <title>Re: Export search results into YYYYMM.csv dynamically based on log date</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Export-search-results-into-YYYYMM-csv-dynamically-based-on-log/m-p/149174#M41702</link>
      <description>&lt;P&gt;Have you tried using the Splunk CLI interface?&lt;/P&gt;

&lt;P&gt;Have a look at the CLI documentation: &lt;A href="http://docs.splunk.com/Documentation/Splunk/6.2.0/SearchReference/CLIsearchsyntax"&gt;http://docs.splunk.com/Documentation/Splunk/6.2.0/SearchReference/CLIsearchsyntax&lt;/A&gt; you might easily combine it with some scripting (PowerShell, Bash, etc) to produce what you need.&lt;/P&gt;

&lt;P&gt;Cheers,&lt;/P&gt;</description>
      <pubDate>Thu, 11 Dec 2014 04:17:06 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Export-search-results-into-YYYYMM-csv-dynamically-based-on-log/m-p/149174#M41702</guid>
      <dc:creator>musskopf</dc:creator>
      <dc:date>2014-12-11T04:17:06Z</dc:date>
    </item>
    <item>
      <title>Re: Export search results into YYYYMM.csv dynamically based on log date</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Export-search-results-into-YYYYMM-csv-dynamically-based-on-log/m-p/149175#M41703</link>
      <description>&lt;P&gt;Hi Henry,&lt;/P&gt;

&lt;P&gt;try this,&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;sourcetype=x,as_log ID | table _time ID mcn begin_action Desc _raw | outputcsv [ | stats count | eval filename=strftime(now(), "%Y%m") | return $filename]
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;The above query will help you to get the today's date. your can change the sub search based on your requirement like instead of now() you can use any date param.&lt;/P&gt;

&lt;P&gt;Cheersss!&lt;/P&gt;</description>
      <pubDate>Thu, 11 Dec 2014 04:22:46 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Export-search-results-into-YYYYMM-csv-dynamically-based-on-log/m-p/149175#M41703</guid>
      <dc:creator>vasanthmss</dc:creator>
      <dc:date>2014-12-11T04:22:46Z</dc:date>
    </item>
    <item>
      <title>Re: Export search results into YYYYMM.csv dynamically based on log date</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Export-search-results-into-YYYYMM-csv-dynamically-based-on-log/m-p/149176#M41704</link>
      <description>&lt;P&gt;Hi, &lt;/P&gt;

&lt;P&gt;Thanks for the prompted reply! Vasanthmss! &lt;/P&gt;

&lt;P&gt;SQL used.&lt;BR /&gt;
sourcetype=csms_log date_month=December ID begin.action | join type=outer ID [ search sourcetype=tony ID detail.identity| stats values(detail_identity) as mcn by ID|fields ID mcn] |  table _time ID mcn begin_action  _raw | outputcsv [ | stats count | eval filename=strftime(_time, "%Y%m") | return $filename]&lt;/P&gt;

&lt;P&gt;However, do you have any idea why the CSV generated via outputcsv is in a different format as &lt;BR /&gt;
export to csv (via Web interface) :&lt;/P&gt;

&lt;P&gt;I found _time column display as as 1417622399.196 in above script&lt;BR /&gt;
however, it display correctly if manual export to csv from the browser!&lt;/P&gt;</description>
      <pubDate>Mon, 28 Sep 2020 18:25:21 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Export-search-results-into-YYYYMM-csv-dynamically-based-on-log/m-p/149176#M41704</guid>
      <dc:creator>henry_ty_leung</dc:creator>
      <dc:date>2020-09-28T18:25:21Z</dc:date>
    </item>
    <item>
      <title>Re: Export search results into YYYYMM.csv dynamically based on log date</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Export-search-results-into-YYYYMM-csv-dynamically-based-on-log/m-p/149177#M41705</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;

&lt;P&gt;if you are getting epoch time in your output csv you can convert the _time like this,&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| eval time=strftime(_time,"%Y-%m-%d %H:%M:%S")
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;So your search would be like this,&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;sourcetype=csms_log date_month=December ID begin.action | join type=outer ID [ search sourcetype=tony ID detail.identity| stats values(detail_identity) as mcn by ID|fields ID mcn]  | eval time=strftime(_time,"%Y-%m-%d %H:%M:%S") | table time ID mcn begin_action _raw | outputcsv [ | stats count | eval filename=strftime(_time, "%Y%m") | return $filename]
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Accept this answer if its solves your query.&lt;/P&gt;

&lt;P&gt;Cheerrs!&lt;/P&gt;</description>
      <pubDate>Thu, 11 Dec 2014 21:14:35 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Export-search-results-into-YYYYMM-csv-dynamically-based-on-log/m-p/149177#M41705</guid>
      <dc:creator>vasanthmss</dc:creator>
      <dc:date>2014-12-11T21:14:35Z</dc:date>
    </item>
    <item>
      <title>Re: Export search results into YYYYMM.csv dynamically based on log date</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Export-search-results-into-YYYYMM-csv-dynamically-based-on-log/m-p/149178#M41706</link>
      <description>&lt;P&gt;check the above answer&lt;/P&gt;</description>
      <pubDate>Thu, 11 Dec 2014 21:17:23 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Export-search-results-into-YYYYMM-csv-dynamically-based-on-log/m-p/149178#M41706</guid>
      <dc:creator>vasanthmss</dc:creator>
      <dc:date>2014-12-11T21:17:23Z</dc:date>
    </item>
    <item>
      <title>Re: Export search results into YYYYMM.csv dynamically based on log date</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Export-search-results-into-YYYYMM-csv-dynamically-based-on-log/m-p/149179#M41707</link>
      <description>&lt;P&gt;Hi Vasanthmss&lt;/P&gt;

&lt;P&gt;I have tried the sql that you have provided, however it stilll not able to return the right filename...any ideas ? &lt;BR /&gt;
do i need to get an earliest time as the filename from below ? &lt;/P&gt;

&lt;P&gt;Thanks&lt;/P&gt;

&lt;P&gt;sourcetype=csms_log date_month=December ID begin.action | join type=outer ID [ search sourcetype=tony ID detail.identity| stats values(detail_identity) as mcn by ID|fields ID mcn]  | eval time=strftime(_time,"%Y-%m-%d %H:%M:%S") | table time ID mcn begin_action _raw | outputcsv [ | stats count | eval filename=strftime(_time, "%Y%m") | return $filename]&lt;/P&gt;

&lt;P&gt;Henry&lt;/P&gt;</description>
      <pubDate>Mon, 28 Sep 2020 18:22:40 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Export-search-results-into-YYYYMM-csv-dynamically-based-on-log/m-p/149179#M41707</guid>
      <dc:creator>henry_ty_leung</dc:creator>
      <dc:date>2020-09-28T18:22:40Z</dc:date>
    </item>
  </channel>
</rss>

