Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 9 Jan 2003 17:30:44 +0100
From:      Stijn Hoop <stijn@win.tue.nl>
To:        Rob <rob@deathbeforedecaf.net>
Cc:        "BigBrother (BigB3)" <bigbrother@bonbon.net>, Duncan Anker <d.anker@au.darkbluesea.com>, freebsd-questions@freebsd.org
Subject:   Re: Renaming files with spaces in the name to files without spaces..
Message-ID:  <20030109163044.GG938@pcwin002.win.tue.nl>
In-Reply-To: <200301091519.h09FJIK7000567@goo.0x7e.net>
References:  <20030108175539.W65616@bigb3server.bbcluster.gr> <200301091519.h09FJIK7000567@goo.0x7e.net>

next in thread | previous in thread | raw e-mail | index | archive | help

--V32M1hWVjliPHW+c
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable

On Fri, Jan 10, 2003 at 01:49:18AM +1030, Rob wrote:
> > 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.
>=20
> But if you do this, won't the spaces be mistaken for filename separators?

No, he has quotes around his $file, and the `` part replaces spaces,
so this should work. Witness:

$ touch "a b" c
$ for i in *; do echo "arg $i endarg"; done
arg a b endarg
arg c endarg

Another solution is using a find & awk combo, which makes it work
recursively (ie one commandline instead of one per directory):

$ find -d . -name '* *' | awk -F/ '{ OFS =3D "/"; o =3D $0; gsub(" ", "_", =
$NF); print "mv \"" o "\" \"" $0 "\"" }' | sh

This can probably be written in a shorter way by awk gurus, I'm just
trying to learn it and this was a good exercise, which is the reason
I'm replying to this post :)

HTH,

--Stijn

--=20
The rain it raineth on the just
	And also on the unjust fella,
But chiefly on the just, because
	The unjust steals the just's umbrella.

--V32M1hWVjliPHW+c
Content-Type: application/pgp-signature
Content-Disposition: inline

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.1 (FreeBSD)

iD8DBQE+HaO0Y3r/tLQmfWcRArXFAJ9tglUM+mPKXU+RW7grjfJ5Nn2A9gCffWPn
HcsZeVca5J85XhZIKjNC3bQ=
=goWy
-----END PGP SIGNATURE-----

--V32M1hWVjliPHW+c--

To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-questions" in the body of the message




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