Baike.dev
All toolsOnline toolsAI codingTrendingOpen sourceNewsSubmit
Log in
< Back to tools
C

csvtk

> 数据库
Open source

A cross-platform, efficient and practical CSV/TSV toolkit in Golang

1.2K stars0 likes1 views
WebsiteGitHub

About

A cross-platform, efficient and practical CSV/TSV toolkit in Golang

csvtk - a cross-platform, efficient and practical CSV/TSV toolkit

  • Documents: http://bioinf.shenwei.me/csvtk ( Usage, Tutorial and FAQs). 中文介绍
  • Source code: https://github.com/shenwei356/csvtk
  • Latest version:

Introduction

Similar to FASTA/Q format in field of Bioinformatics, CSV/TSV formats are basic and ubiquitous file formats in both Bioinformatics and data science.

People usually use spreadsheet software like MS Excel to process table data. However this is all by clicking and typing, which is not automated and is time-consuming to repeat, especially when you want to apply similar operations with different datasets or purposes.

You can also accomplish some CSV/TSV manipulations using shell commands, but more code is needed to handle the header line. Shell commands do not support selecting columns with column names either.

csvtk is convenient for rapid data investigation and also easy to integrate into analysis pipelines. It could save you lots of time in (not) writing Python/R scripts.

Table of Contents

  • Introduction
  • Table of Contents
  • Features
  • Subcommands
  • Installation
    • Method 1: Download binaries (latest stable/dev version)
    • Method 2: Install via Pixi
    • Method 3: Install via conda (latest stable version)
    • Method 4: Install via homebrew
    • Method 5: For Go developer (latest stable/dev version)
    • Method 6: For ArchLinux AUR users (may be not the latest)
  • Command-line completion
  • Compared to csvkit
  • Examples
  • Acknowledgements
  • Contact
  • License
  • Starchart

Features

  • Cross-platform (Linux/Windows/Mac OS X/OpenBSD/FreeBSD)
  • Light weight and out-of-the-box, no dependencies, no compilation, no configuration
  • Fast, multiple-CPUs supported (some commands)
  • Practical functions provided by N subcommands
  • Support STDIN and gzipped input/output file, easy being used in pipe
  • Seamless support for xz (.xz), zstd (.zst), Bzip2 (.bz2), LZ4 (.lz4) formats
  • Most of the subcommands support unselecting fields and fuzzy fields, e.g. -f "-id,-name" for all fields except "id" and "name", -F -f "a.*" for all fields with prefix "a.".
  • Support some common plots (see usage)
  • Seamless support for data with meta line (e.g., sep=,) of separator declaration used by MS Excel

Subcommands

59 subcommands in total.

Information

  • headers: prints headers
  • dim: dimensions of CSV file
  • nrow: print number of records
  • ncol: print number of columns
  • summary: summary statistics of selected numeric or text fields (groupby group fields)
  • watch: online monitoring and histogram of selected field
  • corr: calculate Pearson correlation between numeric columns

Format conversion

  • pretty: converts CSV to a readable aligned table
  • csv2tab: converts CSV to tabular format
  • tab2csv: converts tabular format to CSV
  • space2tab: converts space delimited format to TSV
  • csv2md: converts CSV to markdown format
  • csv2rst: converts CSV to reStructuredText format
  • csv2json: converts CSV to JSON format
  • csv2xlsx: converts CSV/TSV files to XLSX file
  • xlsx2csv: converts XLSX to CSV format

Set operations

  • head: prints first N records
  • concat: concatenates CSV/TSV files by rows
  • sample: sampling by proportion
  • cut: select and arrange fields
  • grep: greps data by selected fields with patterns/regular expressions
  • uniq: unique data without sorting
  • freq: frequencies of selected fields
  • inter: intersection of multiple files
  • filter: filters rows by values of selected fields with arithmetic expression
  • filter2: filters rows by awk-like arithmetic/string expressions
  • join: join files by selected fields (inner, left and outer join)
  • split splits CSV/TSV into multiple files according to column values
  • splitxlsx: splits XLSX sheet into multiple sheets according to column values
  • comb: compute combinations of items at every row

Edit

  • fix: fix CSV/TSV with different numbers of columns in rows
  • fix-quotes: fix malformed CSV/TSV caused by double-quotes
  • del-quotes: remove extra double-quotes added by fix-quotes
  • add-header: add column names
  • del-header: delete column names
  • rename: renames column names with new names
  • rename2: renames column names by regular expression
  • replace: replaces data of selected fields by regular expression
  • round: round float to n decimal places
  • comma: make numbers more readable by adding commas
  • mutate: creates new columns from selected fields by regular expression
  • mutate2: creates a new column from selected fields by awk-like arithmetic/string expressions
  • mutate3: create a new column from selected fields with Go-like expressions
  • fmtdate: format date of selected fields

Transform

  • transpose: transposes CSV data
  • sep: separate column into multiple columns
  • gather: gather columns into key-value pairs, like tidyr::gather/pivot_longer
  • spread: spread a key-value pair across multiple columns, like tidyr::spread/pivot_wider
  • unfold: unfold multiple values in cells of a field
  • fold: fold multiple values of a field into cells of groups
  • long2matrix: convert the long format to a matrix
  • matrix2long: convert a matrix to the long format

Ordering

  • sort: sorts by selected fields
  • shuf: shuffle rows

Ploting

  • plot see usage
    • plot hist histogram
    • plot box boxplot
    • plot line line plot and scatter plot
    • plot bar plot bar chart

Misc

  • cat stream file and report progress
  • version print version information and check for update
  • genautocomplete generate shell autocompletion script (bash|zsh|fish|powershell)

Installation

Download Page

csvtk is implemented in Go programming language, executable binary files for most popular operating systems are freely available in release page.

Method 1: Download binaries (latest stable/dev version)

Just download compressed executable file of your operating system, and decompress it with tar -zxvf *.tar.gz command or other tools. And then:

  1. For Linux-like systems

    1. If you have root privilege simply copy it to /usr/local/bin:

      bash
       sudo cp csvtk /usr/local/bin/
      
    2. Or copy to anywhere in the environment variable PATH:

       mkdir -p $HOME/bin/; cp csvtk $HOME/bin/
  2. For windows, just copy csvtk.exe to C:\WINDOWS\system32.

Method 2: Install via Pixi

pixi global install csvtk

Method 3: Install via conda (latest stable version)

# >= v0.31.0
conda install -c conda-forge csvtk

# > ~/.bash_completion
echo "source ~/.bash_completion" >> ~/.bashrc

Zsh:

# generate completion shell
csvtk genautocomplete --shell zsh --file ~/.zfunc/_csvtk

# configure if never did
echo 'fpath=( ~/.zfunc "${fpath[@]}" )' >> ~/.zshrc
echo "autoload -U compinit; compinit" >> ~/.zshrc

fish:

csvtk genautocomplete --shell fish --file ~/.config/fish/completions/csvtk.fish

Compared to csvkit

csvkit, attention: this table wasn't updated for many years.

Features csvtk csvkit Note
Read Gzip Yes Yes read gzip files
Fields ranges Yes Yes e.g. -f 1-4,6
Unselect fields Yes -- e.g. -1 for excluding first column
Fuzzy fields Yes -- e.g. ab* for columns with name prefix "ab"
Reorder fields Yes Yes it means -f 1,2 is different from -f 2,1
Rename columns Yes -- rename wi

Issues· 0 open

View all issuesOpen on GitHub

No open issues yet, or sync has not completed.

> Tags

Gobioinformaticscommand-linecross-platformcsv

No comments yet. Be the first to share.

> Details

PublishedAug 1, 2026
UpdatedSep 17, 2026
Category数据库
PricingOpen source

> Related tools

P
PostgreSQL
功能强大的开源关系型数据库
R
Redis
内存数据结构存储,常用作缓存与队列
M
MySQL
广泛使用的开源关系型数据库