linux - How to pipe output from grep to cp? -
i have working grep
command selects files meeting condition. how can take selected files grep
command , pipe cp
command?
the following attempts have failed on cp
end:
grep -r "twl" --exclude=*.csv* | cp ~/data/lidar/tmp-ajp2/
cp: missing destination file operand after ‘/home/ubuntu/data/lidar/tmp-ajp2/’ try 'cp --help' more information.
cp `grep -r "twl" --exclude=*.csv*` ~/data/lidar/tmp-ajp2/
cp: invalid option -- '7'
grep -l -r "twl" --exclude=*.csv* | xargs cp -t ~/data/lidar/tmp-ajp2/
explanation:
- grep
-l
option output file names only - xargs convert file list standard input command line arguments
- cp
-t
option specify target directory (and avoid using placeholders)
Comments
Post a Comment