Created
November 12, 2016 19:04
-
-
Save MechMK1/c1668002821c00a824c738bf4cbf90a0 to your computer and use it in GitHub Desktop.
BC2DB
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
#!/bin/bash | |
# Skript: m122_Scripts/BC2SQL_fast.sh | |
DBFILE="SIX_Bankenstamm.db" | |
SRCFILE="SIX_BankenstammCH.csv" | |
TABLENAME="Bankenstamm" | |
if ! [ -r "$SRCFILE" ] | |
then | |
echo "Could not read $SCRFILE. Exiting..." | |
exit 1 | |
fi | |
echo "Preparing database file $DBFILE now..." | |
sqlite3 "$DBFILE" "DROP TABLE IF EXISTS $TABLENAME;" | |
sqlite3 "$DBFILE" "CREATE TABLE Bankenstamm (SortNr INTEGER PRIMARY KEY, BCNr INTEGER, IBAN INTEGER, PZValidierung INTEGER, BCNRIID INTEGER, Landcode TEXT, PostkontoInput TEXT, PostkontoOutput TEXT, SWIFT TEXT, emailDev TEXT, Mutationsdatum INTEGER, Hauptsitz INTEGER, BCART INTEGER, BankInstitut TEXT, SIC INTEGER, eurosic INTEGER, Sprache INTEGER, Kurzbez TEXT, Domizil TEXT, Postadresse TEXT, PLZ TEXT, Ort TEXT, Telefon TEXT, Fax TEXT, Vorwahl TEXT);" | |
echo "Filling database now" | |
echo "" | |
sqlite3 "$DBFILE" -separator ';' ".import $SRCFILE $TABLENAME" 2> /dev/null | |
sqlite3 -header "$DBFILE" "SELECT count(SortNr) as NrOfEntries FROM $TABLENAME" |
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
#!/bin/bash | |
# Skript: m122_Scripts/BC2SQL_slow.sh | |
DBFILE="SIX_Bankenstamm.db" | |
SRCFILE="SIX_BankenstammCH.csv" | |
TABLENAME="Bankenstamm" | |
function getColumn() | |
{ | |
local TMP="$(echo $1 | cut -d ';' -f $2)" | |
if [ -n "$TMP" ] | |
then | |
if [ "$3" == "i" ] | |
then echo "$TMP" | |
else echo "'$TMP'" | |
fi | |
else echo "NULL" | |
fi | |
} | |
if ! [ -r "$SRCFILE" ] | |
then | |
echo "Could not read $SCRFILE. Exiting..." | |
exit 1 | |
fi | |
echo "Preparing database file $DBFILE now..." | |
sqlite3 "$DBFILE" "DROP TABLE IF EXISTS $TABLENAME;" | |
sqlite3 "$DBFILE" "CREATE TABLE Bankenstamm (SortNr INTEGER PRIMARY KEY, BCNr INTEGER, IBAN INTEGER, PZValidierung$ | |
echo "Filling database now" | |
echo "" | |
ALL="$(tail -n +2 $SRCFILE)" | |
echo "$ALL" | while read line | |
do | |
_SORT="$(getColumn "$line" 1 i)" | |
_BCNR="$(getColumn "$line" 2 i)" | |
_TEIL="$(getColumn "$line" 3 i)" | |
_PZ="$(getColumn "$line" 4 i)" | |
_BCNRIDD="$(getColumn "$line" 5 i)" | |
_LAND="$(getColumn "$line" 6)" | |
_POSTIN="$(getColumn "$line" 7)" | |
_POSTOUT="$(getColumn "$line" 8)" | |
_SWIFT="$(getColumn "$line" 9)" | |
_EMAILADR="$(getColumn "$line" 10)" | |
_MUTDA="$(getColumn "$line" 11 i)" | |
_HAUP="$(getColumn "$line" 12 i)" | |
_BC="$(getColumn "$line" 13 i)" | |
_BANK="$(getColumn "$line" 14)" | |
_SIC="$(getColumn "$line" 15 i)" | |
_EURO="$(getColumn "$line" 16 i)" | |
_SPRACHE="$(getColumn "$line" 17 i)" | |
_KURZ="$(getColumn "$line" 18)" | |
_DOMI="$(getColumn "$line" 19)" | |
_POSTAD="$(getColumn "$line" 20)" | |
_PLZ="$(getColumn "$line" 21)" | |
_ORT="$(getColumn "$line" 22)" | |
_TEL="$(getColumn "$line" 23)" | |
_FAX="$(getColumn "$line" 24)" | |
_VOR="$(getColumn "$line" 25)" | |
if [ -n "$_SORT" ] | |
then | |
sqlite3 "$DBFILE" "INSERT INTO $TABLENAME VALUES ($_SORT, $_BCNR, $_TEIL, $_PZ, $_BCNRIDD, $_LAND,$ | |
echo "Added ID: $_SORT" | |
else | |
echo "Invalid Primary Key. Skipped line..." | |
fi | |
done | |
sqlite3 -header "$DBFILE" "SELECT * FROM $TABLENAME"; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment