A Helpful Transmogrifier

A Helpful Transmogrifier

Have a large CSV file and want a quick way to query it? Consider transforming it into a SQLite database. It’s easy! One command will do it:

$ sqlite3 "$sqlite_filename" ".import $csv_filename $table_name --csv"

Here’s a concrete example using airtravel.csv:

$ sqlite3 air.db ".import airtravel.csv air --csv"
$ sqlite3 air.db "SELECT * FROM air WHERE air.Month = 'JAN'"
JAN|  340|  360|  417

Neato! Admittedly the handling of headers and column names isn’t great, but that can be solved with a bit more script-fu (which I’ll leave as an exercise for the reader).

Leave a Reply

Your email address will not be published. Required fields are marked *