csvtool

Work with CSV files from the command line: inspect, cut, sort, transform, and query tabular data.

Category: Text Processing csvtool CSV data tables reports

Install

# Check if it is installed
csvtool --help

# RHEL / Alma / Rocky
sudo dnf install csvtool

# Debian / Ubuntu
sudo apt install csvtool

# openSUSE
sudo zypper install csvtool

# Arch
# Usually not in the base repos; check AUR or use csvkit / miller instead

What it does

csvtool is a command-line utility for working with comma-separated value files. It understands CSV structure better than plain text tools, so it is safer than using cut or awk on files that may contain quoted fields, commas inside data, or header rows.

How it works (mechanical)

  • Reads CSV input from a file or standard input.
  • Parses rows and fields using CSV rules rather than plain character splitting.
  • Applies a subcommand such as cut, sort, transpose, or named-column selection.
  • Writes the transformed CSV or formatted output to standard output.
  • Works best when the input is true CSV and not loosely comma-like text.

Quick Start

# Show a CSV file
csvtool readable sample.csv

# Cut selected columns
csvtool col 1,3 sample.csv

# Sort by a column
csvtool sort -r 2 sample.csv

10 Practical Examples

  1. Print a CSV in a friendlier layout
    csvtool readable inventory.csv
  2. Extract selected columns
    csvtool col 1,4,5 sales.csv
  3. Skip the header, then inspect data
    tail -n +2 sales.csv | csvtool readable -
  4. Sort rows by the second column
    csvtool sort 2 employees.csv
  5. Sort in reverse order
    csvtool sort -r 3 scores.csv
  6. Transpose rows and columns
    csvtool transpose matrix.csv
  7. Count rows quickly
    csvtool height data.csv
  8. Work from a pipeline
    curl -s https://example.com/report.csv | csvtool readable -
  9. Select named columns when supported by local version
    csvtool namedcol Name,Email clients.csv
  10. Combine with column for terminal display
    csvtool readable team.csv | column -t -s ','

Notes & Gotchas

  • Versions differ. Some builds support more subcommands than others, so check csvtool --help locally.
  • Safer than plain text splitting. CSV quoting rules matter, especially when commas appear inside fields.
  • Header handling varies by subcommand. Some actions treat the header like ordinary data unless you manage it explicitly.
  • Not always preinstalled. On some systems, Miller or csvkit may be easier to get.
  • Good for quick work, not full data science. For larger workflows, dedicated tools may be more flexible.

Historical Context

csvtool grew out of the need to manipulate spreadsheet-style data safely from scripts without writing custom parsers. It remains useful for shell-driven reporting, system exports, mailing lists, and quick inspection of structured tabular files.

Modern Equivalent

  • mlr — Miller is often more powerful and flexible for CSV/TSV processing
  • csvkit — a rich suite of CSV tools with strong inspection and SQL-like helpers
  • python -c 'import csv' — useful when custom logic is needed

Related Commands

  • column — make tabular output easier to read in a terminal
  • datamash — summarize and group tabular text
  • awk — general field processing for structured text
  • cut — simple field extraction for delimiter-separated data
  • sort — order lines before or after CSV extraction
  • comm — compare sorted file outputs
  • shuf — randomize rows for sampling
  • nl — number output rows for inspection