Skip to content

Instantly share code, notes, and snippets.

@pantuts
Forked from carlosefonseca/sqlite2csv.sh
Created August 23, 2017 07:47
Show Gist options
  • Save pantuts/2c897939bae29fec5a2d45cb50bf6975 to your computer and use it in GitHub Desktop.
Save pantuts/2c897939bae29fec5a2d45cb50bf6975 to your computer and use it in GitHub Desktop.
Exports all tables in a sqlite database to CSV.
#!/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