#!/bin/bash delete=0 while getopts "d" opt; do case "$opt" in d) delete=1 ;; esac done find . -maxdepth 1 -name 'quoteStore_202*.sqlite3.gz' | sort | while read db; do echo unpacking $db gzip -dc $db >/tmp/xx.sqlite3 echo processing... sqlite3 /tmp/xx.sqlite3 "create table tmp as select timestamp,replace(replace(symbol,'$',''),'.X','') symbol,data from OptionQuotes;" sqlite3 /tmp/xx.sqlite3 'drop table OptionQuotes;' sqlite3 /tmp/xx.sqlite3 'alter table tmp rename to OptionQuotes;' sqlite3 /tmp/xx.sqlite3 '.dump OptionQuotes' | sqlite3 consolidated.sqlite3 echo filling symbols table sqlite3 consolidated.sqlite3 'insert INTO Symbols select DISTINCT Symbol from OptionQuotes where OptionQuotes.Symbol not in (select Symbol from Symbols);' rm /tmp/xx.sqlite3 if [[ "$delete" == "1" ]]; then echo deleting... rm $db else echo moving to processed folder... mkdir -p processedDBs mv $db processedDBs fi done