Splunk Search

Creating unique file name for outputcsv

ShaneNewman
Motivator

I am trying to use this. It will create a file with the correct file name, it just has no contents... Any Ideas?

my command:

`eval_lab_invalid_chars` | `eval_lab_field_errors` | `remove_inactive_tests` | `lab_table_1` | `compendium_status_3_spaces` | `compendium_filter_status(Good)` | `report_date_grouping_lab` | `new_compendium_filter` | `division_lookup` | `compendium_date_format` | `compendium_new_lab_dedup` | `compendium_new_lab_table` | outputcsv [ search index=compendium sourcetype=lab_compendium | head 1 | eval query="All_lab_new_".strftime(now(),"%b_%d_%Y") | fields query | format "" "" "" "" "" ""]`

When I run the search without the outputcsv command I get results...

1 Solution

ShaneNewman
Motivator

We ended up using PowerShell to do the renames and moving the files to the Shared Location that we wanted to use. Changed outputcsv to outputlookup and setup some transforms.conf to setup the initial location of the files.

View solution in original post

0 Karma

ShaneNewman
Motivator

We ended up using PowerShell to do the renames and moving the files to the Shared Location that we wanted to use. Changed outputcsv to outputlookup and setup some transforms.conf to setup the initial location of the files.

0 Karma

ShaneNewman
Motivator

I keep hearing that about a lot of the issues we deal with. I am beginning to wonder if there is something wrong with Windows!

0 Karma

cramasta
Builder

very strange I have not had that happen in my experience so far.

0 Karma

ShaneNewman
Motivator

We are on 4.3.5

That is correct, if I use a static file name it works fine. When using the dynamic name I get a blank file.

I think we are just going to use PowerShell to add the date stamp to the file, after it is generated.

0 Karma

cramasta
Builder

strange, what version are you running?
and to just be clear, when you define the file name like outputcsv filename.csv
its works
but when you use the unique name its a blank file?

0 Karma

ShaneNewman
Motivator

Tried that too, same result.

0 Karma

cramasta
Builder

try this instead for creating the file name

...| outputcsv [ | stats count | eval filename=strftime(now(), "All_lab_new_%b_%d_%Y") | return $filename]

0 Karma

ShaneNewman
Motivator

That is correct, for 450 searches. This file will be used to maintain integrations.

0 Karma

cramasta
Builder

what is the custom name you are trying to accomplish?
All_lab_new_feb_27_2013.csv ?

0 Karma

ShaneNewman
Motivator

Yes, it will work that way.

0 Karma

cramasta
Builder

so you if you just use ...|outputcsv somefile.csv
does it work?

0 Karma
Got questions? Get answers!

Join the Splunk Community Slack to learn, troubleshoot, and make connections with fellow Splunk practitioners in real time!

Meet up IRL or virtually!

Join Splunk User Groups to connect and learn in-person by region or remotely by topic or industry.

Get Updates on the Splunk Community!

Your Path to AgenticOps: AI Experiences for Every Splunk Practitioner

Your Path to AgenticOps: AI Experiences for Every Splunk Practitioner   Watch on demand us for a demo-driven ...

The Data Connection - October 2026

We all have data. Lots of it. But that’s not the problem – it’s understanding what we should we do with it, ...

Beyond the Acceleration Zone: Maximizing Your Success with Splunk Customer Experience ...

Customer success is built on tailored guidance and accessible resources. As a Splunk user, you are encouraged ...