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

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

问题描述

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

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

我可以通过

找到 .|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 找到 .|xargs grep -l email@domain.com

感谢您的帮助.

推荐答案

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

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天全站免登陆