CSVSTACK(1)
π CSVSTACK(1) π
okay bestie, welcome to csvstack, which is part of csvkit (fr fr the whole family of tools is iconic). This page is literally just csvstack Documentation, and it's about to change your whole spreadsheet-adjacent life. π¦
β¨ NAME β¨
csvstack β csvstack Documentation. that's it, that's the name. short. sweet. slays. π
πΈ DESCRIPTION πΈ
so what does she DO? she stacks up the rows from multiple CSV files, and if you want, she can also add a grouping value to each row so you know which file each row came from. lowkey genius. π§
here's the whole usage thing, verbatim, because I would never edit her:
usage: csvstack [-h] [-d DELIMITER] [-t] [-q QUOTECHAR] [-u {0,1,2,3}] [-b]
[-p ESCAPECHAR] [-z FIELD_SIZE_LIMIT] [-e ENCODING] [-S] [-H]
[-K SKIP_LINES] [-v] [-l] [--zero] [-V] [-g GROUPS]
[-n GROUP_NAME] [--filenames]
[FILE [FILE ...]]
Stack up the rows from multiple CSV files, optionally adding a grouping value.
positional arguments:
FILE The CSV file(s) to operate on. If omitted, will accept
input as piped data via STDIN.
optional arguments:
-h, --help show this help message and exit
-g GROUPS, --groups GROUPS
A comma-separated list of values to add as "grouping
factors", one per CSV being stacked. These are added
to the output as a new column. You may specify a name
for the new column using the -n flag.
-n GROUP_NAME, --group-name GROUP_NAME
A name for the grouping column, e.g. "year". Only used
when also specifying -g.
--filenames Use the filename of each input file as its grouping
value. When specified, -g will be ignored.
and now the vibes-based tour of every single one of those, because I'm not skipping a thing:
π positional arguments π
FILEβ the CSV file(s) you want to operate on. you can pass more than one, like[FILE [FILE ...]]. and if you just... don't? she'll accept input as piped data viaSTDINinstead. queen of flexibility. π«Ά
π optional arguments π
-h,--helpβ show this help message and exit. the classic. the icon. use it when you're lost.-g GROUPS,--groups GROUPSβ a comma-separated list of values to add as "grouping factors", one per CSV being stacked. these get added to the output as a new column. and you can name that new column with the-nflag if you want to be fancy about it. π-n GROUP_NAME,--group-name GROUP_NAMEβ a name for the grouping column, like"year". heads up though: this is only used when you also specify-g. no-g, no name, no column. periodt.--filenamesβ use the filename of each input file as its grouping value. and when you do this,-gwill be ignored. I don't make the rules, I just report them. π
β¨ SEE ALSO: Arguments common to all tools. (iykyk β that's where the shared flags live.)
π¨ WARNING, and I need you to READ this one: if you redirect output to an input file like csvstack file.csv > file.csv, the file will grow indefinitely. not a little. indefinitely. that's not a vibe, that's a cursed loop. don't do it bestie π
π¦ EXAMPLES π¦
joining a set of files for different years
csvstack -g 2009,2010 examples/realdata/FY09_EDU_Recipients_by_State.csv examples/realdata/Datagov_FY10_EDU_recp_by_State.csv
two years, two files, one stack, one grouping column. ate. π₯
adding a single column to the left of a CSV
csvstack -n NEWCOL -g "" examples/dummy.csv
a whole new column on the left, name and all. iconic. π
π AUTHOR π
Christopher Groskopf and contributors. we love a collaborator moment. π«Ά
π COPYRIGHT π
2016, Christopher Groskopf and James McKinney. yes ma'am, documented and protected. β¨
and that's the whole page, babe β this was csvkit version 2.2.0, dated Aug 16, 2024. go stack something beautiful. πππΈ
π¦ where this page comes from
- arch rolling: csvkit 2.2.0-2 Β· MIT
- nixos 26.05: csvkit 2.2.0
- nixpkgs unstable: csvkit 2.2.0
- ubuntu resolute: csvkit 2.2.0-1 Β· MIT
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms