Skip to content

Instantly share code, notes, and snippets.

@juev
Created July 15, 2021 07:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save juev/f4e8ca58a600bfe054378e4c0840036d to your computer and use it in GitHub Desktop.
Save juev/f4e8ca58a600bfe054378e4c0840036d to your computer and use it in GitHub Desktop.
convert.sh -- bash script for convert postgresdb dump file to sqlite database
#!/bin/bash
FILE=$1
SQLITE=$2
if [ -z $1 ]; then
echo "convert.sh -- convert postgresdb dump to sqlite database."
echo ""
echo "First argument is dump file"
echo "Second argument is sqlite filename (optional, default value is \`sqlite.db')."
echo ""
echo "Example: $ convert.sh dump.sql sqlite.db"
exit 1
fi
if [ -z $2 ]; then
SQLITE=sqlite.db
fi
echo "Creating backup file..."
cp "$FILE" "$FILE".backup
echo "Parsing dump file..."
sed -i'' 's/true/"t"/g' $FILE
sed -i'' 's/false/"f"/g' $FILE
sed -i'' 's/"public".//g' $FILE
sed -i'' 's/SET/-- SET/g' $FILE
sed -i'' 's/SELECT setval/-- SELECT setval/g' $FILE
sed -i'' '1 i BEGIN;' $FILE
echo "END;" >> $FILE
echo ""
echo "Creating sqlite database..."
sqlite3 $SQLITE < $FILE
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment