Created
June 21, 2022 18:06
-
-
Save ritchieking/ef73efede48873d16bb7be6ff50e1de1 to your computer and use it in GitHub Desktop.
Wrapper for using SQLite on CSV files
This file contains hidden or 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
sqlcsv() { | |
if [ $# -lt 2 ] | |
then | |
echo "USAGE: sqlcsv [filename.csv] [SQL]" | |
echo "In the SQL, refer to the data sourse as [filename]" | |
else | |
filename="$1" | |
dataname=${filename%????} | |
sqlite3 :memory: -cmd '.mode csv' -cmd ".import $filename $dataname" -cmd '.mode markdown' $2 | |
fi | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thank you for the great code!!.
In my environment, the line 9 needs to be changed to
sqlite3 :memory: -cmd '.mode csv' -cmd ".import $filename $dataname" -cmd '.mode markdown' -cmd "$2"
then the command works. Thanks!!