使用grep来查找文件中的内容,如果匹配,则移动它们 [英] Use grep to find content in files and move them if they match
本文介绍了使用grep来查找文件中的内容,如果匹配,则移动它们的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
使用grep生成我需要移动的文件列表:
grep -L -r'Subject : \[垃圾邮件\]' 。
如何将此列表传递给mv命令并将文件移动到其他位置?
解决方案
grep -L -Z -r'Subject:\ [SPAM\]'。 | x表示输出零(\\\\\\\\\\\\\\\\\\\\\\\\' 0)在文件名之后(因此空格不用作分隔符)。
xargs -0
$ c
表示将\0解释为分隔符。
然后
-I {} mv {} DIR
表示用文件名替换 {}
,所以你得到 mv文件名DIR
。 p>
I'm using grep to generate a list of files I need to move:
grep -L -r 'Subject: \[SPAM\]' .
How can I pass this list to the mv command and move the files somewhere else?
解决方案 grep -L -Z -r 'Subject: \[SPAM\]' . | xargs -0 -I{} mv {} DIR
The -Z means output with zeros (\0) after the filenames (so spaces are not used as delimeters).
xargs -0
means interpret \0 to be delimiters.
Then
-I{} mv {} DIR
means replace {}
with the filenames, so you get mv filenames DIR
.
这篇关于使用grep来查找文件中的内容,如果匹配,则移动它们的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文