Bash: Count the number of databases in a gzip compressed mysqldump
A simple bash one-liner!
gunzip -c /path/to/backup/mysqldump.sql.gz | grep -E "^CREATE DATABASE" | wc -l
Breaking this down..
This prints the contents of a gzip compressed mysqldump to the terminal
gunzip -c /path/to/backup/mysqldump.sql.gz
Grep for lines that start with CREATE DATABASES…
grep -E "^CREATE DATABASE"
Count the number of create database lines..
wc -l
So to count the number of tables it’s just a simple change to…
gunzip -c /path/to/backup/mysqldump.sql.gz | grep -E "^CREATE TABLE" | wc -l