shell script pattern matching

Hi,
I need to create a shell script through which i need to populate email addresses in email columns of database table in mysql. Let say if email contains yahoo, hotmail, gtalk than email addresses need to move in their respective columns.

# !/bin/sh

yim="example@yahoo.com"
msn="example@hotmail.com"
gtalk="example@gmail.com"

case $yim in
*yahoo*)
mysql <<EOF
INSERT INTO db.table yahoo_email VALUES ('$yim');
EOF
case $msn in
*hotmail*)
mysql<<EOF
INSERT INTO db.table yahoo_email VALUES ('$msn');
EOF
esac;;

What should be the appropriate way to do this kind of job done. Please reply me as soon as possible.

Thanks,
Irfan

What's the problem with your existing code? Is it not working as you expect?

I presume for the second example you meant to insert into the "hotmail_email" column, not "yahoo_email".

I would do something like this:

#!/bin/sh

#email="example@yahoo.com"
#email="example@hotmail.com"
email="example@gmail.com"

case $email in
        *@yahoo.*)
		table=yahoo_email
		;;
	*@hotmail.*)
		table=hotmail_email
		;;
	*)
		table=standard_email
		;;
esac

mysql<<EOF
	INSERT INTO db.table $table VALUES ('$email');
EOF

I presume your insert statement will need a "where" clause though...

Thanks for the reply. There is minor misktake in script i already sorted out. Now i have some other problem. which i am saving sql query result in variable. Let say

yahoo=$echo('select yahoo from table | mysql db --skip-column-names')
msn=$echo('select msn from table | mysql db --skip-column-names')

which results

yahoo=NULL
msn=NULL

now i want to compare the results that if yahoo and msn is NULL than don't do anything and if yahoo and msn variables contains email addresses than update another table with those values.

my if condition is not working. Please help me out to sort out this issue.

if [[ -n "$yahoo" && -n "$msn" ]]
then
echo "email found. NOT NULL"
else
echo "email are NULL"
fi

It display result "email are NULL"
while it should display "email found. NOT NULL"
because yahoo & msn both variables contains NULL. Please help me how to compare NULL.
Thanks in advance

~Irfan~

I think you mean "||", not "&&".

Why are you writing it in shell script? The MySQL language is quite powerful, you could just do something like "insert into newtable select address from yahoo_email where address not null" or similar (that's pseudo-code, but you can hopefully see what I mean).