textql
Execute SQL against structured text like CSV or TSV
A command-line tool that runs SQL queries directly on CSV and TSV files without importing them into a database, using an in-memory SQLite engine behind the scenes.
textql is a command-line tool that lets you run SQL queries directly against CSV and TSV files, without first importing them into a database. If you have a spreadsheet exported as a CSV and want to filter rows, group data, or join two files together, you can write a SQL statement and feed the files straight to textql rather than opening a database tool or writing a custom script.
The tool loads your files into an in-memory SQLite database behind the scenes, runs your query, and prints the results. Because everything stays in memory by default, there is no database file left behind when you are done, unless you specifically ask it to save one. It also accepts data piped in from other command-line tools, which lets you chain it into standard Unix workflows.
Several quality-of-life features are included. Numbers and common date formats are automatically detected, so you rarely need to cast columns manually. A shorthand SQL syntax lets you drop the SELECT and FROM keywords for simple queries. You can load multiple files or entire directories at once, and join across them as if they were separate tables. Output can go to stdout or a file, with options for the delimiter, pretty-printing, and whether to include a header row.
Installation on a Mac is one line with Homebrew. It can also be built from source using Go, or run inside Docker. An optional extension library adds statistical functions like standard deviation, median, and quartiles if you need more than what SQLite provides by default.
The project is written in Go and released under the MIT license. It is a practical shortcut for anyone who regularly deals with structured text files and wants to ask questions of the data without standing up a full database.
Where it fits
- Filter and group rows in a CSV file using SQL without opening Excel or a database tool.
- Join two CSV files together and query them as if they were separate database tables.
- Chain textql into Unix pipelines to process piped data from other command-line tools with SQL.