Unless you have an extremely long list of banned domains, grep -v
is enough. The mostflag -f
allows you to do exactly what you want:
grep -vf Banned.txt Emails.txt
If you want to do something more complicated bit is actuallyout of the list of banned addresses, e.g. impose that they match the whole of the domain, you'll need to generate a regex from your Banned
file:
cat Banned.txt | tr "\n" "|" | sed -e 's,|$|,$\\|,'g' | sed -e "s's,|\\|$,\\|,g"'
gives the desired
@gotmail.com\|@cmailcom$\|@cmail.com\|@uorcom$\|@uor.eduedu$
Then:
cat Banned.txt | tr "\n" "|" | sed -e 's,|$|,$\\\\|,'g' | sed -e "s's,|\\|$,\\\\|,g"' | xargs -i grep -v '{}' Emails.txt
(doubling the number of escapes \
as they're being evaluated when going through xargs
)
EDIT
Actually, there's a. This will match and remove grep[email protected]
flag,but not e.g. -f[email protected]
, which can do the whole preparation work for you.
grep -vf Banned.txt Emails.txt
I keep the above answer as it can be a usefaul bases for more complicated tasks.