[q] Run SQL queries against a CSV file

Created on November 30, 2026

The q command can query CSV files using SQL. Save the following text as dummy.csv, including the header row.

name,some_number
Tokyo,1500
Saitama,20
Hokkaido,30000

This query selects rows where some_number is 20.

q -d "," -H -O "select * from dummy.csv where some_number = 20"
  • -d sets the input delimiter.
  • -H treats the first row as column names.
  • -O includes the column names in the output.
name,some_number
Saitama,20
Shell command