1

I have a requirement to check if exists clause for all DROP TABLE statements.

If IF EXISTS clause is not present, the script should print it. Below is my code. It works correctly, However I have to check this for all cases. Below scenario works only for uppercase.

for f in $FILES
do
result=`grep "DROP \+TABLE" "$f" | grep -v "IF \+EXISTS"` # -v inverts the match
if [ ! -z $result ]
then
echo 'IF EXISTS clause not found ' $f ':' $result 
fi
done
1
  • echo $f | tr '[a-z]' '[A-Z]' Commented May 4, 2018 at 12:07

1 Answer 1

1

You can use grep's -i option:

grep -i "DROP \+TABLE" "$f" | grep -iv "IF \+EXISTS"

From grep's man page:

-i, --ignore-case

Ignore case distinctions in both the PATTERN and the input files. (-i is specified by POSIX.)

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.