Format SQLite Output So Columns Are Evenly Spaced and Padded

No matter what tab length you choose, you will eventually run into a situation where your columns aren't aligned.

I know you want to do this via post-processing, but you should know that if you set SQLite's .mode option to columns, you'll get the kind of output you want. The column widths will adjust to the length of the longest row. Since you apparently don't want headers, there's a setting for that, too. So

.mode columns
.headers off

will do what you want. These settings will last through your entire session, no matter how many queries you make. Here's an example of real output from one of my databases:

Column-formatted SQLite output (click to expand/collapse)
JVI v. Universal                Edward H. Rice          3823
Cevasco v. Amtrak, et al.       Richard E. Snyder       3854
Bailey v. Chicago               Jordan Marsh            3910
New York Crane Collapse         Joseph DeDonato         3915
Elwood Fire                     David L. Laveck         3922
Logue v. ITW                    Benjeman L. Nichols     3923
Moradi v. Chicago               Elizabeth A. Freidheim  3936
Torres v. McDermott             Carol P. Woosley        3938
Petrielle v. Martin Plumbing    Jeffrey T. Lahners      3940
3501 S. Francisco               Elizabeth A. Freidheim  3951
Mwesigwa v. DAP                 Steve Heine             3970
Montrose Water Main Break       John H. Ehrlich         3985
JCI Polycarbonate Pan Cracking  Charles Obosu           3986

If you insist on post-processing, search for tools that reformat Markdown tables. The output you have is essentially Markdown.

4 Likes