<?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 Dynamic naming of files with outputcsv in Getting Data In</title>
    <link>https://community.splunk.com/t5/Getting-Data-In/Dynamic-naming-of-files-with-outputcsv/m-p/24829#M3970</link>
    <description>&lt;P&gt;We've got Splunk running at a customer site and one of the things that they want is to be able to get regular statistics on their incoming events and then output the stats into a format they can use with their general reporting tools. (We told them they can do it all in Splunk, but I guess they like the graphical tools they've got. Whatever. Customer is king, right?) We've got a scheduled search running that gets the stats that they want and outputs it to a csv file and it is working fine. &lt;/P&gt;

&lt;P&gt;However the name of the output file is always the same, the one that we specified in our search string. So, I was wondering if it is possible to dynamically name the output file using basic data from the search, like maybe "sourcetype_date_hour.csv" or something like that. Can this be done? &lt;/P&gt;</description>
    <pubDate>Wed, 12 Jan 2011 08:48:00 GMT</pubDate>
    <dc:creator>gpburgett</dc:creator>
    <dc:date>2011-01-12T08:48:00Z</dc:date>
    <item>
      <title>Dynamic naming of files with outputcsv</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/Dynamic-naming-of-files-with-outputcsv/m-p/24829#M3970</link>
      <description>&lt;P&gt;We've got Splunk running at a customer site and one of the things that they want is to be able to get regular statistics on their incoming events and then output the stats into a format they can use with their general reporting tools. (We told them they can do it all in Splunk, but I guess they like the graphical tools they've got. Whatever. Customer is king, right?) We've got a scheduled search running that gets the stats that they want and outputs it to a csv file and it is working fine. &lt;/P&gt;

&lt;P&gt;However the name of the output file is always the same, the one that we specified in our search string. So, I was wondering if it is possible to dynamically name the output file using basic data from the search, like maybe "sourcetype_date_hour.csv" or something like that. Can this be done? &lt;/P&gt;</description>
      <pubDate>Wed, 12 Jan 2011 08:48:00 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/Dynamic-naming-of-files-with-outputcsv/m-p/24829#M3970</guid>
      <dc:creator>gpburgett</dc:creator>
      <dc:date>2011-01-12T08:48:00Z</dc:date>
    </item>
    <item>
      <title>Re: Dynamic naming of files with outputcsv</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/Dynamic-naming-of-files-with-outputcsv/m-p/24830#M3971</link>
      <description>&lt;P&gt;Sure can. A subsearch can do it for you. &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;&amp;lt;your search&amp;gt; | outputcsv [ | stats count | eval search=strftime(now(), "filename_%Y_%m_%d_%H"") | fields search]
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;The &lt;CODE&gt;| stats count&lt;/CODE&gt; is just a cheap trick to create a single row.  That row will have a 'count' field whose value is zero.  I eval another field called 'search' and then use the fields clause to restrict to just that one field.   And then subsearches are special-cased when they're given only a single field called 'search'  (or 'query').  If they see that then they will return just the value of the field out into the outer search, not a whole fieldName=value term. &lt;/P&gt;</description>
      <pubDate>Wed, 12 Jan 2011 12:41:12 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/Dynamic-naming-of-files-with-outputcsv/m-p/24830#M3971</guid>
      <dc:creator>sideview</dc:creator>
      <dc:date>2011-01-12T12:41:12Z</dc:date>
    </item>
  </channel>
</rss>

