I am trying to delete erroneous emails based on finding the email address in the file via Linux CLI.
I can get the files with
find . | xargs grep -l email@domain.com
But I cannot figure out how to delete them from there as the following code doesn't work.
rm -f | xargs find . | xargs grep -l email@domain.com
Thank you for your assistance.
You can use
find
's-exec
and-delete
, it will only delete the file if thegrep
command succeeds. Usinggrep -q
so it wouldn't print anything, you can replace the-q
with-l
to see which files had the string in them.