我需要在一些文件中找到一个文本字符串。这将给我一个清单:
find . -type f -print0 | xargs -0 grep -il "google"
然后,我需要将这些文件复制到一个文件夹中,并重新命名它们。所以我想我需要把它们再吹到这样的地方
| xargs -0 -n1 -I '{}' cp '{}' ../testTarget/{}_RECOVERED唉:
find . -type f -print0 | xargs -0 grep -il "google" |
xargs -0 -n1 -I '{}' cp '{}' ../testTarget/{}_RECOVERED结果:cp: {}: No such file or directory
请指教
发布于 2013-07-06 16:03:35
find . -type f -print0 | xargs -0 grep -lh "google" | xargs -I % cp % ../testTarget/%_RECOVERED或
find SOURCE/ -type f -print0 | xargs -0 grep -lh "SEARCH_STRING" | xargs -I % cp % TARGET_DIR/%_RECOVERED发布于 2013-07-04 08:02:10
for i in `ls -1tr`
{
SEARCH_STRING_LINE_NO=`grep -n SEARCH_STRING i | cut -d: -f1`;
if [ SEARCH_STRING_LINE_NO > 0 ] then
cp i folder_path_where_u_want_to_copy
fi
}用要查找的文本字符串替换SEARCH_STRING。
将folder_path_where_u_want_to_copy替换为要移动包含SEARCH_STRING的文件的文件夹路径
这应该将包含SEARCH_STRING的文件复制到folder_path_where_u_want_to_copy文件夹中。
我还没有测试这段代码,因为我现在还没有unix盒,但是至少它应该给你一个方法的想法。
发布于 2013-07-04 08:13:24
下面的命令将grep的pattern和copy文件到您想要的位置。
find /path/to/search -type f -exec grep -q "pattern" '{}' ';' -exec cp '{}' /path/to/copy ';'一旦文件被复制,您就可以使用rename命令相应地重命名它们。
https://stackoverflow.com/questions/17461738
复制相似问题