From owner-freebsd-questions@FreeBSD.ORG Tue Feb 17 07:24:45 2004 Return-Path: Delivered-To: freebsd-questions@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id EE55816A4CE for ; Tue, 17 Feb 2004 07:24:45 -0800 (PST) Received: from mxfep02.bredband.com (mxfep02.bredband.com [195.54.107.73]) by mx1.FreeBSD.org (Postfix) with ESMTP id 2315543D1D for ; Tue, 17 Feb 2004 07:24:45 -0800 (PST) (envelope-from dion@bredband.net) Received: from Hecate.my.hell ([213.113.217.186] [213.113.217.186]) by mxfep02.bredband.com with SMTP id <20040217152443.BOBE4996.mxfep02.bredband.com@Hecate.my.hell>; Tue, 17 Feb 2004 16:24:43 +0100 Date: Tue, 17 Feb 2004 16:24:11 +0100 From: Peder Blom To: Dru Message-Id: <20040217162411.4f5f6d14.dion@bredband.net> In-Reply-To: <20040216163818.R609@genisis.domain.org> References: <20040216163818.R609@genisis.domain.org> X-Mailer: Sylpheed version 0.9.9 (GTK+ 1.2.10; i386-portbld-freebsd4.9) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit cc: questions@freebsd.org Subject: Re: copying files with same name X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 17 Feb 2004 15:24:46 -0000 On Mon, 16 Feb 2004 16:49:37 -0500 (EST) Dru 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).