LinuxCommandLibrary

rec2csv

Export GNU recutils records to CSV format

TLDR

Convert recfile to CSV
$ rec2csv [file.rec] > [output.csv]
copy
Select specific fields
$ rec2csv -f [field1,field2] [file.rec]
copy
Select record type
$ rec2csv -t [Type] [file.rec]
copy
Include header
$ rec2csv -H [file.rec]
copy

SYNOPSIS

rec2csv [options] [file]

DESCRIPTION

rec2csv converts GNU recutils plain-text database files into CSV format for import into spreadsheets, databases, or other tools that consume tabular data. It reads recfile records (structured as key-value pairs separated by blank lines) and outputs them as comma-separated rows with optional column headers via the -H flag.
The -t flag selects a specific record type when a recfile contains multiple types, and -f limits output to specified fields. It can be combined with recsel in a pipeline to first filter records before converting to CSV. Part of the GNU recutils toolkit.

PARAMETERS

-t, --type type

Select record type.
-f, --fields fields
Fields to output (comma-separated).
-H, --headers
Include column headers.
-s, --sort field
Sort by field.
-n, --num n
Limit number of records.

EXAMPLES

$ # Basic conversion
rec2csv contacts.rec > contacts.csv

# With headers
rec2csv -H books.rec > books.csv

# Select fields
rec2csv -f Name,Email,Phone contacts.rec

# Specific type
rec2csv -t Book -f Title,Author library.rec

# With selection
recsel -e "Price > 10" items.rec | rec2csv -H
copy

RECFILE FORMAT

$ Name: John Doe
Email: john@example.com
Phone: 555-1234

Name: Jane Smith
Email: jane@example.com
Phone: 555-5678
copy

CAVEATS

Multi-line field values may need special handling. Part of GNU recutils package.

HISTORY

rec2csv is part of GNU recutils by Jose E. Marchesi for managing plain text databases.

SEE ALSO

recsel(1), recins(1), recdel(1), csv2rec(1)

> TERMINAL_GEAR

Curated for the Linux community

Copied to clipboard