Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save ejhayes/5674480 to your computer and use it in GitHub Desktop.
Save ejhayes/5674480 to your computer and use it in GitHub Desktop.
Iterates over sql files, imports them into a dummy db, gets information about table structure, prints out 3 sample rows, drops the table.
#!/bin/bash
for DB_FILE in $(ls *.sql); do
echo "Using $DB_FILE"
head -c $(expr length "Using $DB_FILE") < /dev/zero | tr '\0' '='
echo
mysql erictest2 < $DB_FILE
mysql erictest2 --batch --silent -e 'show tables' | xargs -I tbl bash -c "echo Table structure for \'tbl\' && mysql erictest2 -t -e 'desc tbl' && mysql erictest2 -t -e 'select * from tbl limit 3\G; drop table tbl;'"
echo
done > out.txt
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment