Splunk® Enterprise

Search Reference

Splunk Enterprise version 7.0 is no longer supported as of October 23, 2019. See the Splunk Software Support Policy for details. For information about upgrading to a supported version, see How to upgrade Splunk Enterprise.
This documentation does not apply to the most recent version of Splunk® Enterprise. For documentation on the most recent version, go to the latest release.

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.

Syntax

outputcsv [append=<bool>] [create_empty=<bool>] [dispatch=<bool>] [usexml=<bool>] [singlefile=<bool>] [<filename>]

Optional arguments

append
Syntax: append=<bool>
Description: If append=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 create_empty=true and there are no results, creates a 0 length file. When create_empty=false, no file is created and if append=false, the file is deleted if it previously existed.
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 the $SPLUNK_HOME/var/run/splunk/csv directory. Directory separators are not permitted in the filename. Filenames cannot contain spaces. 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.
singlefile
Syntax: singlefile=<bool>
Description: If singlefile=true and the output spans multiple files, collapses the output 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

The leading underscore is reserved for names of internal fields such as _raw and _time. By default, the internal fields _raw and _time are included in the search results in Splunk Web.

When the outputcsv command is used in the search, there are additional internal fields that are automatically added to the CSV file. The most common internal fields that are added are:

  • _raw
  • _time
  • _indextime

To exclude specific internal fields from the output, you must specify each field separately using the fields command. Specify the fields command before the outputcsv command.. The negative symbol ( - ) specifies to remove the fields.

For example, to remove all internal fields, you specify:

... | fields - _* | outputcsv MyTestCsvFile

To exclude specific internal fields from the output, you must specify each field separately. For example:

... | fields - _raw _indextime _sourcetype _subsecond _serial | outputcsv MyTestCsvFile

Multivalued fields

The outputcsv command merges values in a multivalued field into single space-delimited value.

Distributed deployments

The outputcsv command is not compatible with search head pooling and search head clustering.

The command saves the *.csv file on the local search head in the $SPLUNK_HOME/var/run/splunk/ directory. The *.csv files are not replicated on the other search heads.

Examples

1. Output search results to a CSV file

Output the search results to the 'mysearch.csv' file. The .csv file extension is automatically added to the file name if you don't specify the extension in the search.

... | outputcsv mysearch

2. Exclude internal fields from the output CSV file

You can exclude unwanted internal fields from the output CSV file. In this example, the fields to exclude are _indextime, _sourcetype, _subsecond, and _serial.

index=_internal sourcetype="splunkd" | head 5 | fields - _indextime _sourcetype _subsecond _serial | outputcsv MyTestCsvfile

See also

inputcsv

Answers

Have questions? Visit Splunk Answers and see what questions and answers the Splunk community has using the outputcsv command.

Last modified on 10 October, 2018
outlier   outputlookup

This documentation applies to the following versions of Splunk® Enterprise: 7.0.0, 7.0.1, 7.0.2, 7.0.3, 7.0.4, 7.0.5, 7.0.6, 7.0.7, 7.0.8, 7.0.9, 7.0.10, 7.0.11, 7.0.13


Was this topic useful?







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