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
Career Survey
First 500 qualified respondents will receive a $20 gift card! Tell us about your professional Splunk journey.
Get Updates on the Splunk Community!

Tech Talk Recap | Mastering Threat Hunting

Mastering Threat HuntingDive into the world of threat hunting, exploring the key differences between ...

Observability for AI Applications: Troubleshooting Latency

If you’re working with proprietary company data, you’re probably going to have a locally hosted LLM or many ...

Splunk AI Assistant for SPL vs. ChatGPT: Which One is Better?

In the age of AI, every tool promises to make our lives easier. From summarizing content to writing code, ...