小编典典

删除文件中包含字符串的文件-Linux CLI

linux

我正在尝试通过Linux CLI在文件中查找电子邮件地址的基础上删除错误的电子邮件。

我可以用

find . | xargs grep -l email@domain.com

但是我无法弄清楚如何从那里删除它们,因为以下代码不起作用。

rm -f | xargs find . | xargs grep -l email@domain.com

谢谢您的帮助。


阅读 466

收藏
2020-06-07

共1个答案

小编典典

为了安全起见,我通常将find的输出通过管道传送到awk之类的文件,并创建一个批处理文件,每行均为“ rm filename”

这样,您可以在实际运行它之前对其进行检查,并手动修复用正则表达式难以处理的任何奇数情况

find . | xargs grep -l email@domain.com | awk '{print "rm "$1}' > doit.sh
vi doit.sh // check for murphy and his law
source doit.sh
2020-06-07