Last active
February 10, 2017 09:42
-
-
Save itsliamjones/66856cc8c1d8470db149c88646397373 to your computer and use it in GitHub Desktop.
Export all tables from an SQLite database to CSVs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
# obtains all data tables from database | |
TS=`sqlite3 $1 "SELECT tbl_name FROM sqlite_master WHERE type='table' and tbl_name not like 'sqlite_%';"` | |
# exports each table to csv | |
for T in $TS; do | |
sqlite3 $1 <<! | |
.headers on | |
.mode csv | |
.output $T.csv | |
select * from $T; | |
! | |
done; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment