Snippets

Michael O'Neill Cross File Table/Index Matching

Created by Michael O'Neill last modified
#!/bin/bash
# Prints (CREATE or ALTER) (TABLE or INDEX) statements in SQL_FILE for each table name in LIST_FILE.

if [ "$#" -lt 2 ]; then
	echo "Usage: $0 LIST_FILE SQL_FILE"
	exit 1
fi

while read line; do
	# Strip comments
	sed -e '/^--/d' $2 |\
	# Make each statement its own line
	sed -e ':a;N;$!ba;s/\n/ /g' -e 's/;/;\n/g' -e 's/\ \+/\ /g' |\
	# Grep those lines
	grep -w -i "\(CREATE\|ALTER\)\s\(TABLE\|INDEX\).*$line"
done < $1

Comments (0)

HTTPS SSH

You can clone a snippet to your computer for local editing. Learn more.