csvq
SQL-like query language for csv
csvq is a command line tool to operate CSV files.
You can read, update, delete CSV records with SQL-like query.
You can also execute multiple operations sequentially in managed transactions by passing a procedure as a command argument or a source file.
In the procedure, you can use variables, cursors, temporary tables, and other functions.
Install
Install executable binary
- Download an archive file from release page.
- Extract the downloaded archive and add a binary file in it to your path.
Build from source
Requirements
Go tools (ref. Getting Started - The Go Programming Language)
Build with either of the following two ways
Use go get
$ go get -u github.com/mithrandie/csvq
Build with strict dependencies
- Install GNU Make
$ go get -d github.com/mithrandie/csvq
- Change directory to $GOPATH/github.com/mithrandie/csvq
$ make deps
$ make install
Usage
# Simple query
csvq "select id, name from `user.csv`"
csvq "select id, name from user"
# Specify data delimiter as tab character
csvq -d "\t" "select count(*) from `user.csv`"
# Load from another directory
csvq "select id, name from `/path/to/user.csv`"
csvq -r /path/to "select user.id, user.name, country.name from `user.csv` natural join `country.csv`"
# Load no-header-csv
csvq --no-header "select c1, c2 from user"
# Load from standard input
csvq "select * from stdin" < user.csv
csvq "select *" < user.csv
cat user.csv | csvq "select *"
# Output in JSON format
csvq write -f json "select integer(id) as id, name from user"
# Output to a file
csvq write -o new_user.csv "select id, name from user"
# Show help
csvq -h
More details >> https://mithrandie.github.io/csvq