Giter VIP home page Giter VIP logo

cq's Introduction

cq

Wrapper over sqlite inspired by jq for querying CSVs using SQL

Examples of use

$ cat t/foobar.csv
foo,bar
1,2
$ cq t/foobar.csv -q 'select foo, bar + 10 as bar_2 from foobar;'
foo,bar_2
1,12
$ cat t/barbaz.csv
bar,baz
2,3
$ cq t/* -q 'select foo, baz from foobar, barbaz where foobar.bar = barbaz.bar;'
foo,baz
1,3

The tablenames are the basenames of the files without their optional .csv extension. One can also provide explicit names for the tables in 2 ways. One is with prefix assignment:

$ cq f:=t/foobar.csv b:=t/barbaz.csv -q 'select foo, baz from f, b where f.bar = b.bar;'
foo,baz
1,3

And the other one is with suffix assignment:

$ cq t/foobar.csv=:f t/barbaz.csv=:b -q 'select foo, baz from f, b where f.bar = b.bar;'
foo,baz
1,3

Notice one uses := and the other one is flipped =:. The former looks better when combining with <() process substitution:

cq \
  a:=<(ssh server_a generate_csv) \
  b:=<(ssh server_b produce_different_csv)

The latter works better with brace expansion:

cq a/very/long/path/{long_filename=:a,elsewhere/another_file=:b}

Output headers can be disabled with +H, and re-enabled with -H. The last option overrides the formers so you can set a default in a shell alias.

$ cq +H t/foobar.csv -q 'select foo, bar from foobar;'
1,2

Output mode can be set with -o:

$ cq -o column t/foobar.csv -q 'select foo, bar from foobar;'
foo         bar       
----------  ----------
1           2         

Supported output modes can be listed with sqlite3 <<< '.help mode'.

There's a --help option for more.

cq's People

Contributors

jolmg 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.