Skip to content

Instantly share code, notes, and snippets.

@davide-romanini
Last active August 29, 2015 14:11
Show Gist options
  • Save davide-romanini/be55163e68c432e85c64 to your computer and use it in GitHub Desktop.
Save davide-romanini/be55163e68c432e85c64 to your computer and use it in GitHub Desktop.
INDUCKS sqlite loader
#!/bin/bash
# imports inducks data files into sqlite db
# tested with:
# - UNRAR 5.00 beta 8
# - sqlite 3.8.2 2013-12-06 14:53:30 27392118af4c38c5203a04b8013e1afdb1cebd0d
# before running:
# wget http://coa.inducks.org/inducks/isv.rar
# wget https://gist.githubusercontent.com/davide-romanini/e92f7ce5c582f54a34ea/raw/ba042b6b0debed472519150cdf05093627c11d6a/inducks_sqlite.sql
# cat inducks_sqlite.sql|sqlite3 coa.sqlite
ISV_RAR="isv.rar"
for ISV_PATH in `unrar lb $ISV_RAR|grep '\.isv$'`
do
ISV=$(basename $ISV_PATH)
TABLE=$(basename $ISV_PATH .isv)
echo "Importing $ISV in $TABLE..."
# decompress -> skip header line -> remove last separator;escape ";enclose fields in ""
unrar p -inul $ISV_RAR $ISV_PATH|tail -n +2|sed 's/.$//;s/"/""/g;s/[^\^]*/"&"/g' > $ISV
echo -e ".mode csv\n.separator ^\nDELETE FROM $TABLE;\n.import $ISV $TABLE"|sqlite3 coa.sqlite
rm $ISV
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment