Skip to content
Execute SQL select statements on a CSV file from command line
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Type Name Latest commit message Commit time
Failed to load latest commit information.

Table of content

What is sql4csv?

sql4csv is a simple tool to execute SQL querys direct from commandline on the data of a CSV file.

To execute a SQL statement on a CSV file simple execute the following command:

    scq select distinct author from books.csv

were scq is the name of the command to execute.

In case of a CSV file looking like the following

    Douglas Adams,Doctor Who  
    Douglas Adams,The Hitchhiker's Guide to the Galaxy  
    Terry Pratchet,The Colour of Magic  
    Terry Pratchet,Mort  

the result, printed in the console will be

    Douglas Adams  
    Terry Pratchet

Why your own solution and not using an existing ones?

Because I can :-)

There are a bunch of tools out there to do such a solution. The most impressive is q. Nevertheless scq is written by me to have a project using the new features of Java 8 from scratch.

Also I want to do some automatic type detection for lazy types like dates and datetimes. Reason are the CSV files I sometimes have where dates are written in an ISO like format (2016-8-3 instead of 2016-08-03).

But why do I need such a tool?

It's for my simple statistic stack based on Unix command line tools, R and some simple SQL scripts which I don't want to import to a dedicated RDBMS for only onetime usage.

Download and Installation

  1. Download the latest prebuild version from our homepage:
  2. Unpack the archive with the tool of your choice.
  3. Adjust your PATH environment variable by adding the sql4csv directory.

That's it. Have fun :-)


Using SQL statements direct from a bash command line is problematic. The bash replaces the asterisk (*) sign with the files of the current directory. It's not simple possible to escape this behavior. I work around this with replaceing the * character with

$(head -n 1 filename)

Not a very elegant method but it works.

Escaping additional special bash characters like parenthesis or less- and greater-than equal signs is straight forward with a leading basckslash (\).

from keyword

scq supports space characters in table columns. Nevertheless if a table column contains a space surrounded from, the beahvior is not supported yet.

You can’t perform that action at this time.