outputcsv

Description

If you have Splunk Enterprise, this command saves search results to the specified CSV file on the local search head in the $SPLUNK_HOME/var/run/splunk/csv directory. Updates to $SPLUNK_HOME/var/run/*.csv using the outputcsv command are not replicated across the cluster.

If you have Splunk Cloud, you cannot use this command. Instead, you have these options:

Syntax

Optional arguments

append

Syntax: append=<bool>

Description: If append is true, the command attempts to append to an existing CSV file, if the file exists. If the CSV file does not exist, a file is created. If there is an existing file that has a CSV header already, the command only emits the fields that are referenced by that header. The command cannot append to .gz files.

Default:false

create_empty

Syntax: create_empty=<bool>

Description: If set to true and there are no results, a zero-length file is created. When set to false and there are no results, no file is created. If the file previously existed, the file is deleted.

Default: false

dispatch

Syntax: dispatch=<bool>

Description: If set to true, refers to a file in the job directory in $SPLUNK_HOME/var/run/splunk/dispatch/<job id>/.

filename

Syntax: <filename>

Description: Specify the name of a CSV file to write the search results. This file should be located in $SPLUNK_HOME/var/run/splunk/csv. Directory separators are not permitted in the filename. If no filename is specified, the command rewrites the contents of each result as a CSV row into the _xml field. Otherwise the command writes into a file. The .csv file extension is appended to the filename if the filename has no file extension.

override_if_empty

Syntax: override_if_empty=<bool>

Description: If override_if_empty=true and no results are passed to the output file, the existing output file is deleted, If override_if_empty=false and no results are passed to the output file, the command does not delete the existing output file.

Default: true

singlefile

Syntax: singlefile=<bool>

Description: If singlefile is set to true and the output spans multiple files, collapses it into a single file.

Default:true

usexml

Syntax: usexml=<bool>

Description: If there is no filename, specifies whether or not to encode the CSV output into XML. This option should not be used when invoking the outputcsv from the UI.

Usage

There is no limit to the number of results that can be saved to the CSV file.

Internal fields and the outputcsv command

When the outputcsv command is used there are internal fields that are automatically added to the CSV file. The internal fields that are added to the output in the CSV file are:

_raw

_time

_indextime

_serial

_sourcetype

_subsecond

To exclude internal fields from the output, use the fields command and specify the fields that you want to exclude. For example:

Enter your email address, and someone from the documentation team will respond to you:

Send me a copy of this feedback

Please provide your comments here. Ask a question or make a suggestion.

Feedback submitted, thanks!

You must be logged into splunk.com in order to post comments.
Log in now.

Please try to keep this discussion focused on the content covered in this documentation topic.
If you have a more general question about Splunk functionality or are experiencing a difficulty with Splunk,
consider posting a question to Splunkbase Answers.

0
out of 1000 Characters

Your Comment Has Been Posted Above

We use our own and third-party cookies to provide you with a great online experience. We also use these cookies to improve our products and services, support our marketing campaigns, and advertise to you on our website and other websites. Some cookies may continue to collect information after you have left our website.
Learn more (including how to update your settings) here »