From owner-freebsd-questions Wed Jan 8 15:34:18 2003 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 25FA837B401 for ; Wed, 8 Jan 2003 15:34:17 -0800 (PST) Received: from mail.au.darkbluesea.com (mail.au.darkbluesea.com [203.185.208.1]) by mx1.FreeBSD.org (Postfix) with ESMTP id 1E18D43EE1 for ; Wed, 8 Jan 2003 15:34:15 -0800 (PST) (envelope-from d.anker@au.darkbluesea.com) Received: (qmail 53941 invoked by uid 82); 8 Jan 2003 23:30:07 -0000 Received: from unknown (HELO ?10.0.0.188?) (10.0.0.188) by cam.au.darkbluesea.com with SMTP; 8 Jan 2003 23:30:07 -0000 Subject: Re: Renaming files with spaces in the name to files without spaces.. From: Duncan Anker To: "BigBrother (BigB3)" Cc: freebsd-questions@freebsd.org In-Reply-To: <20030108175539.W65616@bigb3server.bbcluster.gr> References: <20030108175539.W65616@bigb3server.bbcluster.gr> Content-Type: text/plain Organization: Dark Blue Sea Message-Id: <1042068862.1441.3.camel@duncan.au.darkbluesea.com> Mime-Version: 1.0 X-Mailer: Ximian Evolution 1.2.0 Date: 09 Jan 2003 09:34:22 +1000 Content-Transfer-Encoding: 7bit Sender: owner-freebsd-questions@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.ORG On Thu, 2003-01-09 at 02:01, BigBrother (BigB3) wrote: > -----BEGIN PGP SIGNED MESSAGE----- > Hash: SHA1 > > > Sorry for this OT but I am trying for some hours to achieve a massive > rename of files using a simple script and I have not success yet. I want > to rename files like > > "RESULTS OF JAN 01 2002.txt " > > to > > "RESULTS_OF_JAN_01_2002.txt" > > i.e. all the spaces, being substituted by '_', and the last space being > completely removed [yes it has a space after the suffix] > I tried to experiment with sed/awk and creating a sample sh script with > for i in 'ls' .... > > but the i takes values of 'RESULTS' 'OF' 'JAN'. This means that it doesnt > take the full filename as value, but parts of the filenames. > > > Can u please suggest an easy way to implement the massive rename? > If you want to do it for all files in a directory: # for file in *; do mv "$file" `echo $file | sed -e 's/ /_/g'`; done should do the trick. I think Perl is overkill for something this simple. Someone else suggested tr, which probably works, but I've had more success with sed. cheers, Duncan -- The information contained in this email is confidential. If you are not the intended recipient, you may not disclose or use the information in this email in any way. Dark Blue Sea does not guarantee the integrity of any emails or attached files. The views or opinions expressed are the author's own and may not reflect the views or opinions of Dark Blue Sea. Dark Blue Sea does not warrant that any attachments are free from viruses or other defects. You assume all liability for any loss, damage or other consequences which may arise from opening or using the attachments. To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-questions" in the body of the message