删除文件中包含字符串的文件-Linux CLI [英] Delete files with string found in file - linux cli

查看:525
本文介绍了删除文件中包含字符串的文件-Linux CLI的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am trying to delete erroneous emails based on finding the email address in the file via Linux CLI.

我可以使用

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

谢谢您的帮助.

推荐答案

为了安全起见,我通常将find的输出传递给awk之类的东西,并创建一个批处理文件,每行都是"rm filename"

For safety I normally pipe the output from find to something like awk and create a batch file with each line being "rm filename"

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

That way you can check it before actually running it and manually fix any odd edge cases that are difficult to do with a regex

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

这篇关于删除文件中包含字符串的文件-Linux CLI的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆