Caltech Library logo

export-csv

Syntax

    dataset COLLECTION_NAME export-csv OUTPUT_NAME FILTER_EXPR FIELDS_TO_EXPORT COLUMN_HEADINGS

Description

export-csv will render the contents of a collection as a CSV file.

FILTER_EXPR is an expression that evaluates to true or false based on Golang template expressions (see dataset -help filter for more explanation).

FIELDS_TO_EXPORT is a comma separated list of dotpaths (e.g. .id,.title,.pubDate) in the collection’s JSON documents. (see dataset -help dotpath for more explanation of dotpaths)

Usage

In the following examples we will “filter” for all records in a collection so we use the string “true”. The following fields are being exported - ._id,.title, and .pubDate with the following headings – id, title and publication date.

The example blow creates a CSV file named ‘output.csv’. The collection is “publications.ds”.

	dataset publications.ds export-csv titles.csv true '._id,.title,.pubDate' 'id,title,publication date' > output.csv

Related topics: extract, import-csv, import-gsheets, export-gsheets