Am 08.02.2011 19:27, schrieb Mark Knecht: > Hi, > Looking for a simple way to do a big copy at the command line. I > have a bunch of files (maybe 100 right now, but it will grow) that I > can find with locate and grep: > > c2stable ~ # locate Correlation | grep Builder | grep csv > /home/mark/Builder/TF/TF.D-17M-2009_06-2010_11/Correlation/TF.D-17M-2009_06-2010_11-V1.csv > /home/mark/Builder/TF/TF.D-17M-2009_06-2010_11/Correlation/TF.D-17M-2009_06-2010_11-V2.csv > /home/mark/Builder/TF/TF.D-17M-2009_06-2010_11/Correlation/TF.D-17M-2009_06-2010_11-V3.csv > <SNIP> > /home/mark/Builder/TF/TF.D-31M-2009_06-2010_11/Correlation/TF.D-31M-2009_06-2010_11-V4.csv > /home/mark/Builder/TF/TF.D-31M-2009_06-2010_11/Correlation/TF.D-31M-2009_06-2010_11-V5.csv > c2stable ~ # > > I need to copy these files to a new directory > (~mark/CorrelationTests) where I will modify what's in them before > running correlation tests on the contents. > > How do I feed the output of the command above to cp at the command > line to get this done? > > I've been playing with things like while & read but I can't get it right. > > Thanks, > Mark >
locate Correlation | grep Builder | grep csv | xargs -IARG cp ARG ~mark/CorrelationTests -IARG tells xargs to replace the occurrence of ARG in the parameters with the actual parameters read from stdin. or locate Correlation | grep Builder | grep csv | while read file; do cp "$file" ~mark/CorrelationTests; done BTW: Wouldn't grep 'Builder/.*\.csv' match better (some intermediate directory Builder, ending on .csv)? Even easier: locate ~mark/'*/Builder/*.csv' | xargs -IARG cp ARG ~mark/CorrelationTests Warning: I've not tested every line. Use with caution. Hope this helps, Florian Philipp
signature.asc
Description: OpenPGP digital signature