Export all tables in a SQLite3 db to CSV files
#!/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
Written by Carlos Fonseca
Related protips
1 Response
Worked perfectly. Thank you.
over 1 year ago
·
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Sqlite
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#