Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 17 Feb 2004 16:24:11 +0100
From:      Peder Blom <dion@bredband.net>
To:        Dru <dlavigne6@sympatico.ca>
Cc:        questions@freebsd.org
Subject:   Re: copying files with same name
Message-ID:  <20040217162411.4f5f6d14.dion@bredband.net>
In-Reply-To: <20040216163818.R609@genisis.domain.org>
References:  <20040216163818.R609@genisis.domain.org>

next in thread | previous in thread | raw e-mail | index | archive | help
On Mon, 16 Feb 2004 16:49:37 -0500 (EST)
Dru <dlavigne6@sympatico.ca> wrote:

> 
> Okay, I must be missing something obvious here. How do you do a batch
> copy while renaming the destination files? I want to copy all of the
> configure scripts in /usr/ports to ~/scripts. I can get find to find
> the files, I can get sed to rename them, but I can't get the timing
> down right.
> 
> cp -v `find /usr/ports -name configure -print | sed 's:/:=:g'` .
> 
> renames the files nicely (so they're not all named configure), but
> does it too soon--the source no longer exists.
> 
> cp -v `find /usr/ports -name configure -print -exec sed 's:/:=:g' {}
> \;` .
> 
> gives a syntax error (missing }) and
> 
> cp -v `find /usr/ports -name configure -print | sed 's:/:=:g'` .
> 
> has sed complain of extra characters at the end of a p command,
> followed by all my destination files being named configure.
> 
> Is there a way to do this as a one-liner, or does one have to write a
> shell script with a while loop?
> 
> Dru
> _______________________________________________



---
cd ~/scripts

find /usr/ports/ -name configure | awk '{dst=$0;gsub("/","=",dst); \
print "cp",$0,dst}' | sh
---

Pipe the output to less instead of sh to check what actions will be
taken before running the above commands!

This will not work with filenames that contain spaces (easily fixed).




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20040217162411.4f5f6d14.dion>