Last active
August 29, 2015 14:16
-
-
Save cmattoon/b8f870eddc6efa1e137d to your computer and use it in GitHub Desktop.
Extract a table from mysql dump
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
# The basic command that gets run | |
sed -n '/CREATE TABLE.*table/,/UNLOCK TABLES/p' full_database_backup.sql > table.sql |
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
#!/bin/bash | |
INFILE=$(READLINK -f $1); | |
TABLE_NAME=$2 | |
if [ $# -eq 2 ]; then | |
if [ ! -f "$INFILE" ]; then | |
echo "First parameter must be a valid file"; | |
exit 1; | |
fi; | |
if [ ! -r "$INFILE" ]; then | |
echo "Cannot read $INFILE. Do you have permission?"; | |
exit 1; | |
fi; | |
sed -n "/CREATE TABLE.*${TABLE_NAME}/,/UNLOCK TABLES/p" $INFILE; | |
exit 0; | |
else | |
echo "Usage: dbextract [file] [table_name]"; | |
exit 1; | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment