Free · Open source · One binary

SQL for Unix streams and the web.

sqx turns CSV, JSON, logs and plain text into tables you can query straight from your terminal. Built-in functions fetch URLs, read HTML and look up DNS, so one query can join a spreadsheet with a live website.

~/data
cat users.csv | sqx "
  SELECT country, COUNT(*) AS customers
  FROM stdin GROUP BY country"
+---------+-----------+
| country | customers |
+---------+-----------+
| CN      | 1         |
| IN      | 2         |
| MX      | 1         |
| TR      | 1         |
| US      | 1         |
+---------+-----------+

Data in, SQL in the middle, answers out

Pipe in whatever you have. sqx loads it into an in-memory SQLite database, runs your query, and prints the result in the format you need.

Why sqx?

Joining two CSV files, checking which of 500 URLs are broken, or finding an API key leaked in a page should not need a database server, credentials or a throwaway Python script. With sqx, you pipe data in and write the SQL you already know.

Any stream is a table

CSV, TSV, JSON arrays, JSON Lines and plain lines. The format is detected, column types are inferred and messy headers are cleaned up.

Join files on the fly

Load any number of local files or URLs with -f name=path and JOIN them in one query.

Crawl once, query many times

Every http_* and html_* function shares an on-disk cache, so each URL is downloaded once.

HTML without a browser

Pull titles, meta tags, headings, links and attributes out of fetched pages or stored HTML.

Security helpers

DNS A and TXT lookups for SPF and DMARC, private-IP checks, regex extraction, SHA-256 and Shannon entropy.

Nothing else to install

One self-contained binary for macOS, Linux, Windows and FreeBSD. SQLite is built in.

Three things you can do in one line

Join a CSV with a JSON Lines file

sqx -f users=users.csv -f events=events.jsonl "
  SELECT u.name, COUNT(e.id) AS events, ROUND(SUM(e.amount), 2) AS revenue
  FROM users u LEFT JOIN events e ON e.user_id = u.id
  GROUP BY u.id ORDER BY revenue DESC"

Audit a list of URLs

cat urls.txt | sqx -i lines "
  SELECT url, http_status(url) AS status, http_final_url(url) AS final_url, html_title(url) AS title
  FROM stdin"

Check SPF and DMARC for a list of domains

cat companies.csv | sqx "
  SELECT domain,
         CASE WHEN dns_txt_json(domain) LIKE '%v=spf1%' THEN 'yes' ELSE 'MISSING' END AS spf,
         CASE WHEN dns_txt_json('_dmarc.' || domain) LIKE '%v=DMARC1%' THEN 'yes' ELSE 'MISSING' END AS dmarc
  FROM stdin"

More in the cookbook.

Works with the tools you already know

sqx is one more command in your pipeline. Our short guides cover the classic Unix tools it pairs with, with everyday options, examples and links to the full manuals.

Browse all Unix tool guides →

Documentation

Frequently asked questions

How do I query a CSV file with SQL from the command line?

Pipe the file into sqx and query the table named stdin: cat users.csv | sqx "SELECT country, COUNT(*) FROM stdin GROUP BY country". sqx detects the format, cleans up column names and infers numeric types. See Load CSV, JSON and text.

Can I join a CSV file with a JSON file using SQL?

Yes. Load each file as a named table with -f and join them in one query. See Join files.

Does sqx need SQLite or a database server installed?

No. sqx is one self-contained binary with SQLite built in. There is no runtime, server, driver or shared library to install.

Can sqx fetch web pages and extract HTML with SQL?

Yes. Functions such as http_status(url), html_title(url), html_meta(url, 'description') and html_links(url) fetch pages through a persistent cache, so each URL is downloaded only once. See Fetch and parse the web.

Is sqx free and open source?

Yes. sqx is free software released under the GNU General Public License, version 2 or later.