Remove all mistyped emails, unsubscribed emails or bounced emails from Email List

We assume, we have following 3 files,
1. all-exported-emails.txt => this file contains list of all the emails as people have entered in subscribe form.
2. unsubscribed.txt => contains list of emails of people unsubscribed
3. bounced.txt => contains list of emails which we have already tried previosuly sending and have bounced.

 $ vim create_final_email_list.sh 
sort -u all-exported-emails.txt > unique.txt
#bash prepare_csv.sh unique.txt
rm -rf final.txt
while read line
do NEW_MAIL=$line
#remove unwanted character from email
if [ "$NEW_MAIL" == "${NEW_MAIL//[\,\' ]/}" ]
then check=$(grep -r $NEW_MAIL unsubscribed.txt) if [ "$check" = "$NEW_MAIL" ]; then echo "email $NEW_MAIL found in unsubscribed.txt" else check2=$(grep -r $NEW_MAIL bounced.txt) if [ "$check" = "$NEW_MAIL" ]; then echo "email $NEW_MAIL found in bounced.txt" else echo $NEW_MAIL >> final.txt fi fi
else echo "email $NEW_MAIL contains space, comma or quote.. hence ignoring"
fi
done < unique.txt
 $ bash create_final_email_list.sh 
READ  How to check if your machine is Little Endian or Big Endian using C program in Linux

Leave a Reply

Your email address will not be published. Required fields are marked *