Skip to main content
added 11 characters in body
Source Link
Joce
  • 1.1k
  • 1
  • 8
  • 21

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.

Unless you have an extremely long list of banned domains, grep -v is enough. The most complicated bit is actually to generate a regex from your Banned file:

cat Banned.txt | tr "\n" "|" | sed -e 's,|$,,' | sed -e "s,|,\\|,g"

gives the desired

@gotmail.com\|@cmail.com\|@uor.edu

Then:

cat Banned.txt | tr "\n" "|" | sed -e 's,|$,,' | sed -e "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 grep flag, -f, 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.

grep -v is enough. The flag -f allows you to do exactly what you want:

grep -vf Banned.txt Emails.txt

If you want to do something more complicated out 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,\\|$,,'

gives the desired

@gotmail.com$\|@cmail.com$\|@uor.edu$

Then:

cat Banned.txt | tr "\n" "|" | sed -e 's,|,$\\\\|,g' | sed -e 's,\\|$,,' | xargs -i grep -v '{}' Emails.txt

(doubling the number of escapes \ as they're being evaluated when going through xargs). This will match and remove [email protected] but not e.g. [email protected].

added 225 characters in body
Source Link
Joce
  • 1.1k
  • 1
  • 8
  • 21

Unless you have an extremely long list of banned domains, grep -v is enough. The most complicated bit is actually to generate a regex from your Banned file:

cat Banned.txt | tr "\n" "|" | sed -e 's,|$,,' | sed -e "s,|,\\|,g"

gives the desired

@gotmail.com\|@cmail.com\|@uor.edu

Then:

cat Banned.txt | tr "\n" "|" | sed -e 's,|$,,' | sed -e "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 grep flag, -f, 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.

Unless you have an extremely long list of banned domains, grep -v is enough. The most complicated bit is actually to generate a regex from your Banned file:

cat Banned.txt | tr "\n" "|" | sed -e 's,|$,,' | sed -e "s,|,\\|,g"

gives the desired

@gotmail.com\|@cmail.com\|@uor.edu

Then:

cat Banned.txt | tr "\n" "|" | sed -e 's,|$,,' | sed -e "s,|,\\\\|,g" | xargs -i grep -v {} Emails.txt

(doubling the number of escapes \ as they're being evaluated when going through xargs)

Unless you have an extremely long list of banned domains, grep -v is enough. The most complicated bit is actually to generate a regex from your Banned file:

cat Banned.txt | tr "\n" "|" | sed -e 's,|$,,' | sed -e "s,|,\\|,g"

gives the desired

@gotmail.com\|@cmail.com\|@uor.edu

Then:

cat Banned.txt | tr "\n" "|" | sed -e 's,|$,,' | sed -e "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 grep flag, -f, 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.

Source Link
Joce
  • 1.1k
  • 1
  • 8
  • 21

Unless you have an extremely long list of banned domains, grep -v is enough. The most complicated bit is actually to generate a regex from your Banned file:

cat Banned.txt | tr "\n" "|" | sed -e 's,|$,,' | sed -e "s,|,\\|,g"

gives the desired

@gotmail.com\|@cmail.com\|@uor.edu

Then:

cat Banned.txt | tr "\n" "|" | sed -e 's,|$,,' | sed -e "s,|,\\\\|,g" | xargs -i grep -v {} Emails.txt

(doubling the number of escapes \ as they're being evaluated when going through xargs)