A naive approach would be (assuming GNU utilities):
grep -FZlw -f address.list -- *.eml | xargs -r0 rm -f --
Or the same but with the long options as supported by GNU utilities:
grep --fixed-strings \
--null --files-with-matches \
--file address.list \
-- *.eml |
xargs --no-run-if-empty --null \
rm --force --
But that would delete files when addresses are found anywhere in the file, whether it's in the
Reply-To headers, or in the body of the email or in attachments.
Also if the
firstname.lastname@example.org, that would also delete emails for
That also assumes email addresses are formatted the same (same case, no MIME encoding) in the
address.list and in the
If you know exactly how the emails are formatted, for instance if they're always going to contain one and only one occurrence of a line like:
email@example.com is formatted exactly like in your
address.list, then you can do:
sed 's/^/To: /' address.list | grep -xZFlf - -- *.eml | xargs -r0 rm -f --
Which would be more reliable.
Instead of passing the
address.list as a list of words to be found anywhere in the files, we're transforming the search list first with the
editor command to prefix each line with
"To: " so that the fixed string patterns become
To: firstname.lastname@example.org and using
--line-regexp for those (instead of
--word-regexp) to match the full contents of lines e
To: email@example.com doesn't match on
Reply-To: firstname.lastname@example.org for instance).
rm -f with
grep -H '^To:' above if instead of removing the files, you want to check what the
To: header is for the files that are to be removed.