LinuxCommandLibrary

csvstack

Vertical CSV file concatenator

TLDR

Stack multiple CSV files

$ csvstack [file1.csv] [file2.csv] > [combined.csv]
copy
Stack with group column
$ csvstack -g [source1,source2] [file1.csv] [file2.csv]
copy
Name the group column
$ csvstack -g [a,b] -n [source] [file1.csv] [file2.csv]
copy
Stack files without headers
$ csvstack -H [file1.csv] [file2.csv]
copy
Stack with different delimiters
$ csvstack -d ";" [file1.csv] [file2.csv]
copy

SYNOPSIS

csvstack [options] files...

DESCRIPTION

csvstack concatenates multiple CSV files vertically (row-wise). Part of csvkit, it aligns columns by header name and can add a grouping column to track source files.
The tool handles files with different column orders by matching header names, making it robust for combining datasets from different sources.

PARAMETERS

-g names

Add grouping column with values.
-n name
Name for grouping column.
-H, --no-header-row
Inputs have no header row.
--filenames
Use filenames as group values.
-d char
Field delimiter.
-q char
Quote character.
-e encoding
Input encoding.

CAVEATS

All files should have matching columns for clean output. Missing columns filled with empty values. Part of csvkit, requires Python. Headers from first file used if different.

HISTORY

csvstack is part of csvkit, created by Christopher Groskopf in 2011. It simplifies combining multiple data files, a common task in data processing and analysis workflows.

SEE ALSO

csvcut(1), csvlook(1), cat(1), csvjoin(1)

> TERMINAL_GEAR

Curated for the Linux community

Copied to clipboard

> TERMINAL_GEAR

Curated for the Linux community