Skip to content

Instantly share code, notes, and snippets.

@lovasoa
Created September 24, 2018 15:56
Show Gist options
  • Select an option

  • Save lovasoa/7f62823201e803a1c7aea5ba5dd88c3c to your computer and use it in GitHub Desktop.

Select an option

Save lovasoa/7f62823201e803a1c7aea5ba5dd88c3c to your computer and use it in GitHub Desktop.
Convert text a text file to sql statements, inserting a new value per line of text
#!/usr/bin/env bash
echo "CREATE TABLE lines (line TEXT);";
while read line; do
escaped=${line//\'/\'\'};
echo "INSERT INTO lines VALUES ('$escaped');";
done
@lovasoa
Copy link
Copy Markdown
Author

lovasoa commented Sep 24, 2018

Usage

./txt2sql.sh < my_data.txt | sqlite3 lines.db

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