Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- USAGE="\n\x1b[31mUsage:\x1b[0m extract_table_from_mysql_dump.sh my_table /path/to/dump.sql\n\x1b[32mOptional 3rd parameter:\x1b[0m /path/to/export/to\nThe export filename will default to extracted_{my_table}.sql\n"
- if [[ -z "$1" ]] ; then
- printf "$USAGE"
- exit 1
- fi
- # Check the table name was provided
- if [[ -z "$2" ]] ; then
- printf "$USAGE"
- exit 1
- fi
- # Check the input path to the dump was provided
- if [[ -z "$3" ]] ; then
- OUTPUT="~/extracted_$1.sql"
- else
- OUTPUT="$3/extracted_$1.sql"
- fi
- # Check the output path to the dump was provided
- # If not, use a default one
- sed -n -e "/DROP TABLE.*\`$1\`/,/UNLOCK TABLES/p" $2 > $OUTPUT
- # Run.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement