Skip to content

Instantly share code, notes, and snippets.

@lucasff
Last active August 29, 2015 14:04
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 lucasff/a432560f25bb3bd91784 to your computer and use it in GitHub Desktop.
Save lucasff/a432560f25bb3bd91784 to your computer and use it in GitHub Desktop.
Add a prefix on tables of a SQL dump
#!/bin/sh
#
# Simple script for setting table prefixes in SQL-dump
if [ $# != 2 ]; then
cat >&2 << EOH
This is Drupal database prefixer.
Usage:
$0 prefix original_db.sql > prefixed_db.sql
- all tables will be prefixed with 'prefix'
EOH
exit 1;
fi
PRFX=$1;
sed "s/^CREATE TABLE /CREATE TABLE $PRFX/i;
s/^INSERT INTO /INSERT INTO $PRFX/i;
s/^REPLACE /REPLACE $PRFX/i;
s/^ALTER TABLE /ALTER TABLE $PRFX/i" $2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment