Terminal GuideTerminal Guide

xsv

Dev Tools
macOSLinuxWindows
Rust

Fast CSV toolkit written in Rust.

Official Website

Features

FastIndexingJoiningStatisticsSQL-like Queries

Installation

Homebrew
brew install xsv
Cargo (Rust)
cargo install xsv

Why use xsv?

xsv is a Swiss Army knife for CSV data processing. Written in Rust for maximum performance, it enables searching, indexing, joining, and transforming CSV files with SQL-like commands—all from the command line.

Lightning Fast

Built with Rust for blazing-fast CSV processing. Handles gigabytes of data efficiently.

SQL-like Queries

Perform SELECT, JOIN, GROUP BY operations on CSV files with intuitive command syntax.

Flexible Filtering

Search, filter, and select specific rows and columns with regex support.

Rich Features

Index files for fast access, split files, transpose data, and calculate statistics.

Installation

Installation
# macOS (Homebrew)
brew install xsv

# Ubuntu/Debian
cargo install xsv

# Arch Linux
pacman -S xsv

# From source
git clone https://github.com/BurntSushi/xsv
cd xsv
cargo install --path .

# Download pre-built binary
wget https://github.com/BurntSushi/xsv/releases/download/1.0.1/xsv-1.0.1-x86_64-unknown-linux-musl.tar.gz
tar xf xsv-1.0.1-x86_64-unknown-linux-musl.tar.gz
sudo mv xsv /usr/local/bin/

Basic Usage

Inspecting CSV Files

Inspection
# View column headers
xsv headers data.csv

# Display file statistics
xsv stats data.csv

# Show first few rows
xsv slice -l 5 data.csv

# Count rows
xsv count data.csv

# View specific columns
xsv select 1,3,5 data.csv | head

Selecting and Filtering

Selection & Search
# Select specific columns by name
xsv select name,email,age data.csv

# Select by index
xsv select 1,2,4 data.csv

# Select range of columns
xsv select 1-5 data.csv

# Search for rows containing text
xsv search 'John' data.csv

# Filter with regex
xsv search '.*@gmail\.com' data.csv --select email

Data Transformation

Transformations
# Rename columns
xsv rename 'old_name,new_name' data.csv

# Convert to different delimiter
xsv fmt --crlf data.csv  # Windows line endings
xsv fmt --tab data.csv   # Tab-separated

# Create new column from expression
xsv eval 'full_name' '"{first_name} {last_name}"' data.csv

# Sort by column
xsv sort -s age data.csv

# Sort in reverse
xsv sort -R -s age data.csv

Common Patterns

Joining CSV Files

Joining
# Join two CSV files on common column
xsv join --no-case user_id users.csv id orders.csv

# Left join with different column names
xsv join --left --left-columns id --right-columns user_id users.csv orders.csv

# Inner join
xsv join --inner employee_id departments.csv id employees.csv

Statistics and Analysis

Statistics
# Get detailed statistics
xsv stats --all data.csv

# Stats for specific columns
xsv stats --select age,salary data.csv

# Show stats with cardinality
xsv stats --cardinality data.csv

# Find distinct values
xsv select category data.csv | sort | uniq -c

Splitting and Slicing

Splitting
# Split into chunks of 1000 rows
xsv split -s 1000 data.csv split-dir/

# Get rows 100-200
xsv slice -i 100 -l 100 data.csv

# Get specific row range
xsv slice 50..150 data.csv

# Split by column value
xsv groupby country data.csv | xsv split -s 100 - split-by-country/

Indexing for Performance

Indexing
# Create index file for fast access
xsv index large-file.csv

# Now search and access operations are faster
xsv search 'value' large-file.csv

# List indexed files
ls -la large-file.csv*

# Index files in batch
for f in *.csv; do xsv index "$f"; done

Advanced Features

Field Evaluation

Evaluation
# Create calculated column
xsv eval 'total' '$price * $quantity' data.csv

# Conditional column
xsv eval 'status' 'if $age >= 18 { "adult" } else { "minor" }' data.csv

# Format existing column
xsv eval 'email' 'tolower($email)' data.csv

# Math operations
xsv eval 'percentage' '($value / $total) * 100' data.csv

Data Deduplication

Deduplication
# Remove duplicate rows
xsv dedup data.csv

# Deduplicate by specific column
xsv dedup -s email data.csv

# Sort before deduplication
xsv sort -s email data.csv | xsv dedup -s email

# Count duplicates
xsv select email data.csv | sort | uniq -c | sort -rn

Format Conversion

Format Conversion
# Convert to JSON
xsv fmt --crlf data.csv > data-crlf.csv

# Create delimited format for databases
xsv fmt --delimiter '|' data.csv > data-pipe.csv

# Convert with quoting style
xsv fmt --quote-always data.csv

# Escape special characters
xsv select name,description data.csv | xsv fmt --escape --delimiter ','

Combining with Other Tools

Combination
# Filter with grep then process
grep 'status=active' data.csv | xsv select name,email

# Process each row with xargs
xsv select url data.csv | xargs -I {} curl {}

# Combine stats from multiple files
cat file1.csv file2.csv | xsv stats

# Use with awk for complex filtering
xsv select name,salary data.csv | awk -F, '$2 > 50000'

Command Reference

CommandDescriptionExample
countCount number of rowsxsv count data.csv
headersList column headersxsv headers data.csv
selectChoose columnsxsv select name,age
searchSearch for patternxsv search 'value'
joinJoin files on columnxsv join id f1.csv f2.csv
sortSort by columnxsv sort -s age
dedupRemove duplicatesxsv dedup -s id

Tips

  • Always use xsv index on large files for significant performance improvements on subsequent operations
  • Use xsv count to quickly get row count without loading entire file
  • Combine with standard Unix tools like grep, sort, and awk for more complex operations
  • Use -s flag with column names to be case-insensitive with column selection
  • The stats command with --cardinality helps identify unique values in columns
Written by Dai AokiPublished: 2026-01-20

Related Articles

Explore More