-
-
Save brock/9dcacefc390e8faa8fc8 to your computer and use it in GitHub Desktop.
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/sh | |
if [ $# -ne 2 ] | |
then | |
echo "Usage: $0 <postgresql sql dump> <db_name>" >&2 | |
exit 1 | |
fi | |
db_file=$1 | |
db_name=$2 | |
if [ ! -f $db_file -o ! -r $db_file ] | |
then | |
echo "error: $db_file not found or not readable" >&2 | |
exit 2 | |
fi | |
grep -b "^\connect" $db_file | grep -m 1 -A 1 "$db_name$" | while read line | |
do | |
bytes=`echo $line | cut -d: -f1` | |
if [ -z "$start_point" ] | |
then | |
start_point=$bytes | |
else | |
end_point=$bytes | |
fi | |
done | |
if [ -z "$start_point" -o -z "$end_point" ] | |
then | |
echo "error: start or end not found" >&2 | |
exit 3 | |
fi | |
db_length=`expr $end_point - $start_point` | |
tail -c +$start_point $db_file | head -c $db_length | tail +3 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment