如何将输出从grep传递到cp? [英] How to pipe output from grep to cp?
本文介绍了如何将输出从grep传递到cp?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个有效的grep
命令,该命令选择满足特定条件的文件.如何从grep
命令中获取所选文件并将其通过管道传输到cp
命令中?
I have a working grep
command that selects files meeting a certain condition. How can I take the selected files from the grep
command and pipe it into a cp
command?
cp
端的以下尝试失败:
grep -r "TWL" --exclude=*.csv* | cp ~/data/lidar/tmp-ajp2/
cp:之后缺少目标文件操作数 ‘/home/ubuntu/data/lidar/tmp-ajp2/’尝试使用'cp --help'获得更多信息 信息.
cp: missing destination file operand after ‘/home/ubuntu/data/lidar/tmp-ajp2/’ Try 'cp --help' for more information.
cp `grep -r "TWL" --exclude=*.csv*` ~/data/lidar/tmp-ajp2/
cp:无效选项-'7'
cp: invalid option -- '7'
推荐答案
grep -l -r "TWL" --exclude=*.csv* | xargs cp -t ~/data/lidar/tmp-ajp2/
说明:
- grep
-l
选项仅输出文件名 - xargs将文件列表从标准输入转换为命令行参数
- cp
-t
选项以指定目标目录(并避免使用占位符)
- grep
-l
option to output file names only - xargs to convert file list from the standard input to command line arguments
- cp
-t
option to specify target directory (and avoid using placeholders)
这篇关于如何将输出从grep传递到cp?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文