The documentation for SQLite isn't super clear on how to work with external files directly from the command line. Here's how to read and process SQL from an input file:

sqlite3 database.db < input.sql

And this captures the output to a file as well:

sqlite3 database.db < query.sql > results.txt

Super useful for automating work without having to jump into SQLite itself.

(Alternative approaches are cat input.sql | sqlite3 database.db and cat query.sql | sqlite3 database.db > results.txt, respectively, but they aren't as aesthetically pleasing.)