csvkit csvcut: Select and Reorder CSV Columns
csvcut picks columns out of a CSV by name or position, like cut but CSV-aware so quoted commas do not break it.
Unix cut splits on a delimiter and mangles quoted fields. csvcut parses real CSV, so a comma inside a quoted value stays put.
What it does
csvcut reads a CSV and writes only the requested columns, selected by name or 1-based index with -c, in the order you list them. -n prints the column names with their indices so you can discover them first.
Common usage
# list column names and their indices
csvcut -n data.csv
# select columns by name (reordered)
csvcut -c name,email data.csv
# select by index, and exclude with -C
csvcut -c 1,3 data.csv
csvcut -C password data.csv # everything except passwordOptions
| Flag | What it does |
|---|---|
| -c, --columns <list> | Columns to keep, by name or 1-based index |
| -C, --not-columns <list> | Columns to exclude |
| -n, --names | Print column names and indices, then exit |
| -d, --delimiter <c> | Input delimiter (e.g. tab) |
| -e, --encoding <enc> | Input encoding (e.g. latin-1) |
| -z, --maxfieldsize <n> | Raise the max field size limit |
In CI
Strip sensitive or noisy columns from a CSV artifact before publishing it: csvcut -C token,secret report.csv > public.csv. Run csvcut -n first in a debug step to confirm the column layout the rest of your pipeline assumes.
Common errors in CI
csvcut: command not found means csvkit is not installed; pip install csvkit. UnicodeDecodeError: utf-8 codec can't decode byte means the file is not UTF-8; add -e latin-1. Column N is invalid means an index out of range or a name that does not match the header (csvkit is case-sensitive). Very long fields raise field larger than field limit; pass -z 1000000.