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

Popular posts from this blog

javascript - Chart.js (Radar Chart) different scaleLineColor for each scaleLine -

apache - Error with PHP mail(): Multiple or malformed newlines found in additional_header -

java - Android – MapFragment overlay button shadow, just like MyLocation button -