Skip to main content

Execute SQL-like queries on .csv and .tsv files.

# To query .csv file by specifying the delimeter as ',':
q -d',' "SELECT * from path/to/file"

# To query .tsv file:
q -t "SELECT * from path/to/file"

# To query file with header row:
q -ddelimiter -H "SELECT * from path/to/file"

# To read data from stdin; '-' in the query represents the data from stdin:
output | q "select * from -"

# To join two files (aliased as f1 and f2 in the example) on column c1, a common column:
q "SELECT * FROM path/to/file f1 JOIN path/to/other_file f2 ON (f1.c1 = f2.c1)"

# To format output using an output delimeter with an output header line (note: command will output column names based on the input file header or the column aliases overridden in the query):
q -Ddelimiter -O "SELECT column as alias from path/to/file"