xsv
A fast CSV command-line toolkit for slicing, indexing, selecting, searching, and joining CSV files.
xsv is a suite of fast CSV manipulation commands bundled into a single binary.
Rather than reaching for awk, cut, or a Python script every time you want to
explore a CSV file, xsv gives you a consistent, composable set of subcommands
that pipe cleanly together.
Features
- Indexing — build an index for instant random access and parallel operations on large files
- Slicing and selecting — extract specific rows, columns, or ranges without loading the whole file
- Searching — filter rows by regex match on one or more columns
- Joining — perform inner, left, right, and full outer joins between two CSV files
- Sorting and deduplicating — sort by one or more columns, remove duplicate rows
- Statistics — compute count, min, max, mean, standard deviation, and median for each column
- Frequency tables — count distinct values per column
- Flattening — convert a CSV into a human-readable vertical key/value format
- Fast — built with performance in mind; handles files far larger than memory when indexed
Installation
cargo install xsv
Or via your package manager:
# Debian / Ubuntu
apt install xsv
# Fedora
dnf install xsv
# macOS
brew install xsv
# Arch Linux
yay -S xsvUsage
# Show the first 5 rows with headers
xsv slice -l 5 data.csv | xsv table
# Select specific columns
xsv select name,age,email data.csv
# Search for rows where any field matches a pattern
xsv search "New York" data.csv
# Search in a specific column
xsv search -s city "New York" data.csv
# Print summary statistics for each column
xsv stats data.csv | xsv table
# Count distinct values in the "country" column
xsv frequency -s country data.csv
# Join two CSV files on a common column
xsv join id users.csv user_id orders.csv
# Sort by a column
xsv sort -s age data.csv
# Remove duplicate rows
xsv dedup data.csv
# Pretty-print as an aligned table (great for terminal viewing)
xsv table data.csv
# Convert to a vertical key/value view (useful for wide CSVs)
xsv flatten data.csv
# Count rows
xsv count data.csvIndexing for large files
For large CSV files, building an index unlocks parallel processing and instant random access:
# Build an index
xsv index data.csv
# Now slice operations are instant, even on huge files
xsv slice -s 100000 -l 10 data.csv
# Stats run in parallel across cores
xsv stats --everything data.csvComposing commands
xsv subcommands pipe naturally:
# Find all users from Germany, select name and email, pretty-print
xsv search -s country Germany users.csv \
| xsv select name,email \
| xsv tableSee also
qsv is an actively maintained fork of
xsv with many additional subcommands and ongoing bug fixes, worth considering
if you need features beyond what xsv provides.