Skip to content

Instantly share code, notes, and snippets.

@ritchieking
Created June 21, 2022 18:06
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ritchieking/ef73efede48873d16bb7be6ff50e1de1 to your computer and use it in GitHub Desktop.
Save ritchieking/ef73efede48873d16bb7be6ff50e1de1 to your computer and use it in GitHub Desktop.
Wrapper for using SQLite on CSV files
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
}
@AtsushiSakai
Copy link

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!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment