On Tue, Feb 8, 2011 at 11:02 AM, Florian Philipp <li...@binarywings.net> wrote:
> 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.
>

Thanks! This worked nicely and is relatively easy to remember.

> or
>
> locate Correlation | grep Builder | grep csv | while read file; do
> cp "$file" ~mark/CorrelationTests; done
>

This is what I was trying to do but was unsuccessful.

> BTW: Wouldn't grep 'Builder/.*\.csv' match better (some intermediate
> directory Builder, ending on .csv)?
>

Yes, that does seem to work. I guess that's grepping for the path of a
file starting with Builder and ending with CSV?

Good one.

> 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

It did very much. Thanks!

Now to work on modifying the files, again with a loop for all the
files in ~mark/CorrelationTests

- Mark

Reply via email to