From owner-freebsd-questions Wed Jan 8 8:39: 0 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 4C78237B401 for ; Wed, 8 Jan 2003 08:38:59 -0800 (PST) Received: from grillolja.cs.umu.se (grillolja.cs.umu.se [130.239.40.17]) by mx1.FreeBSD.org (Postfix) with ESMTP id 575F343ED1 for ; Wed, 8 Jan 2003 08:38:58 -0800 (PST) (envelope-from tdv94ped@cs.umu.se) Received: from localhost (localhost [127.0.0.1]) by amavisd-new (Postfix) with ESMTP id 1F7569FA2; Wed, 8 Jan 2003 17:38:52 +0100 (MET) Received: from kvist.cs.umu.se (kvist.cs.umu.se [130.239.40.192]) (using TLSv1 with cipher EDH-RSA-DES-CBC3-SHA (168/168 bits)) (No client certificate requested) by grillolja.cs.umu.se (Postfix) with ESMTP id 0644C9F9C; Wed, 8 Jan 2003 17:38:50 +0100 (MET) Date: Wed, 8 Jan 2003 17:38:49 +0100 (MET) From: Paul Everlund To: "BigBrother (BigB3)" Cc: freebsd-questions@freebsd.org Subject: Re: Renaming files with spaces in the name to files without spaces.. In-Reply-To: <20030108175539.W65616@bigb3server.bbcluster.gr> Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII X-Virus-Scanned: by amavisd-new amavisd-new-20020630 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 Wed, 8 Jan 2003, BigBrother (BigB3) wrote: > 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? Maybe something like this? #!/usr/bin/perl @ls = `ls`; chomp @ls; foreach (@ls) { $before = $_; if(/\ $/) { chop $_; } s/\ /_/g; system("mv \"$before\" $_"); } This is the kind of question which will come up with hundreds of solutions from hundreds of persons. :-) Before using above script you should make a backup first! Best regards, Paul To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-questions" in the body of the message