A tool to query CSV files using SQL.
This tool is powered by PHP MySQL Engine. SQL syntax which is supported by PHP MySQL Engine is supported.
A query is given as the first argument of the command. Data is read from stdin by default.
$ cat data.csv
id,name
1,John
2,Alice
3,Dave
4,Bob
$ csv-query 'SELECT * FROM stdin WHERE id < 4 ORDER BY name' < data.csv
id,name
2,Alice
3,Dave
1,John
$ cat data.csv
1 John
2 Alice
3 Dave
4 Bob
$ csv-query -H --delimiter=$'\t' 'SELECT MIN(c1), MAX(c1) FROM stdin' < data.csv
min max
1 4
csv-query
can get file paths as second and subsequent arguments. The file's base name (without extension) will be a table name.
$ cat /path/to/user.csv
id,name
1,John
2,Alice
3,Dave
$ cat /another/dir/birthday.csv
user_id,birthday
1,2000/11/1
3,2002/6/5
$ csv-query 'SELECT name, birthday FROM user INNER JOIN birthday ON user.id = birthday.user_id' /path/to/user.csv /another/dir/birthday.csv
name,birthday
John,2000/11/01
Dave,2002/06/05
CSV delimiters used for both input and output. Default value is comma (,
).
CSV delimiters used for input and output, respectively. These options override -d
option.
Declares that the first line of the input is not a header line. Each column is named c1
, c2
, c3
, and so on.
Suppresses to print a header line.
Outputs version number and exits.
Outputs a help message and exits.