GithubHelp home page GithubHelp logo

csv-query's Introduction

csv-query

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.

Usage

Basic usage

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

Common options

$ 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

Joining tables

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

Options

-d, --delimiter

CSV delimiters used for both input and output. Default value is comma (,).

--delimiter-in, --delimiter-out

CSV delimiters used for input and output, respectively. These options override -d option.

-H, --no-header-in

Declares that the first line of the input is not a header line. Each column is named c1, c2, c3, and so on.

-O, --no-header-out

Suppresses to print a header line.

-V, --version

Outputs version number and exits.

--help

Outputs a help message and exits.

csv-query's People

Contributors

takaram avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.