A cross-platform, efficient and practical CSV/TSV toolkit in Golang
A cross-platform, efficient and practical CSV/TSV toolkit in Golang
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.
csvkit-f "-id,-name" for all fields except "id" and "name",
-F -f "a.*" for all fields with prefix "a.".sep=,) of separator declaration used by MS Excel59 subcommands in total.
Information
headers: prints headersdim: dimensions of CSV filenrow: print number of recordsncol: print number of columnssummary: summary statistics of selected numeric or text fields (groupby group fields)watch: online monitoring and histogram of selected fieldcorr: calculate Pearson correlation between numeric columnsFormat conversion
pretty: converts CSV to a readable aligned tablecsv2tab: converts CSV to tabular formattab2csv: converts tabular format to CSVspace2tab: converts space delimited format to TSVcsv2md: converts CSV to markdown formatcsv2rst: converts CSV to reStructuredText formatcsv2json: converts CSV to JSON formatcsv2xlsx: converts CSV/TSV files to XLSX filexlsx2csv: converts XLSX to CSV formatSet operations
head: prints first N recordsconcat: concatenates CSV/TSV files by rowssample: sampling by proportioncut: select and arrange fieldsgrep: greps data by selected fields with patterns/regular expressionsuniq: unique data without sortingfreq: frequencies of selected fieldsinter: intersection of multiple filesfilter: filters rows by values of selected fields with arithmetic expressionfilter2: filters rows by awk-like arithmetic/string expressionsjoin: join files by selected fields (inner, left and outer join)split splits CSV/TSV into multiple files according to column valuessplitxlsx: splits XLSX sheet into multiple sheets according to column valuescomb: compute combinations of items at every rowEdit
fix: fix CSV/TSV with different numbers of columns in rowsfix-quotes: fix malformed CSV/TSV caused by double-quotesdel-quotes: remove extra double-quotes added by fix-quotesadd-header: add column namesdel-header: delete column namesrename: renames column names with new namesrename2: renames column names by regular expressionreplace: replaces data of selected fields by regular expressionround: round float to n decimal placescomma: make numbers more readable by adding commasmutate: creates new columns from selected fields by regular expressionmutate2: creates a new column from selected fields by awk-like arithmetic/string expressionsmutate3: create a new column from selected fields with Go-like expressionsfmtdate: format date of selected fieldsTransform
transpose: transposes CSV datasep: separate column into multiple columnsgather: gather columns into key-value pairs, like tidyr::gather/pivot_longerspread: spread a key-value pair across multiple columns, like tidyr::spread/pivot_widerunfold: unfold multiple values in cells of a fieldfold: fold multiple values of a field into cells of groupslong2matrix: convert the long format to a matrixmatrix2long: convert a matrix to the long formatOrdering
Ploting
Misc
cat stream file and report progressversion print version information and check for updategenautocomplete generate shell autocompletion script (bash|zsh|fish|powershell)csvtk is implemented in Go programming language,
executable binary files for most popular operating systems are freely available
in release page.
Just download compressed
executable file of your operating system,
and decompress it with tar -zxvf *.tar.gz command or other tools.
And then:
For Linux-like systems
If you have root privilege simply copy it to /usr/local/bin:
sudo cp csvtk /usr/local/bin/
Or copy to anywhere in the environment variable PATH:
mkdir -p $HOME/bin/; cp csvtk $HOME/bin/For windows, just copy csvtk.exe to C:\WINDOWS\system32.
pixi global install csvtk# >= v0.31.0
conda install -c conda-forge csvtk
# > ~/.bash_completion
echo "source ~/.bash_completion" >> ~/.bashrcZsh:
# generate completion shell
csvtk genautocomplete --shell zsh --file ~/.zfunc/_csvtk
# configure if never did
echo 'fpath=( ~/.zfunc "${fpath[@]}" )' >> ~/.zshrc
echo "autoload -U compinit; compinit" >> ~/.zshrcfish:
csvtk genautocomplete --shell fish --file ~/.config/fish/completions/csvtk.fishcsvkitcsvkit, 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 |
No open issues yet, or sync has not completed.