Skip to content

Instantly share code, notes, and snippets.

@robla
Created November 25, 2017 01:27
Show Gist options
  • Save robla/9b14fecc52a4352ebf4d5a0620ed260f to your computer and use it in GitHub Desktop.
Save robla/9b14fecc52a4352ebf4d5a0620ed260f to your computer and use it in GitHub Desktop.
sqlite3-csv.sh: dump an table from sqlite db as csv
#!/bin/bash
# sqlite3-csv: dump an table from sqlite db as csv
summary="$0: dump an sqlite db as csv"
usageline=" usage: $0 thisdb [thistable]"
usage="${summary}\n\n${usageline}\n\n"
if [ -z "$1" ]; then
printf "$usage"
exit;
elif [ ! -f "$1" ]; then
echo "$1 isn't a file..."
printf "$usage"
exit;
else
thisdb="$1"
fi
if [ -z "$2" ]; then
thistable='*'
else
thistable="$2"
fi
if [ "$thistable" == '*' ]; then
echo "Tables: "
sqlite3 places.sqlite .tables
exit;
else
sqlite3 -header -csv "$thisdb" "select * from $thistable;"
exit
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment