2016-11-05 18:39:47 +00:00
# q
> Execute SQL-like queries on .csv and .tsv files.
2019-05-23 11:56:50 +01:00
> More information: <https://harelba.github.io/q>.
2016-11-05 18:39:47 +00:00
2021-01-31 17:05:18 +00:00
- Query `.csv` file by specifying the delimiter as ',':
2016-11-05 18:39:47 +00:00
`q -d',' "SELECT * from {{path/to/file}}"`
2021-01-31 17:05:18 +00:00
- Query `.tsv` file:
2016-11-05 18:39:47 +00:00
`q -t "SELECT * from {{path/to/file}}"`
- Query file with header row:
`q -d{{delimiter}} -H "SELECT * from {{path/to/file}}"`
2022-12-04 07:53:34 +00:00
- Read data from `stdin` ; '-' in the query represents the data from `stdin` :
2016-11-05 18:39:47 +00:00
`{{output}} | q "select * from -"`
- 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)"`
2017-07-20 19:53:15 +01:00
- Format output using an output delimiter 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):
2016-11-05 18:39:47 +00:00
`q -D{{delimiter}} -O "SELECT {{column}} as {{alias}} from {{path/to/file}}"`