Perl rename utility assistance

Polytropon freebsd at edvax.de
Tue Dec 16 19:39:17 UTC 2014


On Tue, 16 Dec 2014 11:20:50 -0800, jungle Boogie wrote:
> Hello Kevin,
> On 16 December 2014 at 10:40,  <kpneal at pobox.com> wrote:
> > A little bit of quick scripting should do this without needing a
> > rename or whatever program.
> >
> > #! /bin/sh
> >
> > oname="$1"
> > nname=$(echo "$oname" | sed 's/_/ /')
> >
> > set -x
> > mv "$oname" "$nname"
> 
> What if you have a directory full of files you want to update?

See:

#!/bin/sh
set -x
for oname in *.*; do
	nname=`echo "${oname}" | sed 's/_/ /'`
	mv "${oname]" "${nname}"
done

Not that it is _wrong_ to deal with file name iteration
that way. Take my example as "works in many cases, but
you shouldn't do it that way". Instead, go ahead and read:

http://www.dwheeler.com/essays/fixing-unix-linux-filenames.html

http://www.dwheeler.com/essays/filenames-in-shell.html

Then return to do it better. ;-)


-- 
Polytropon
Magdeburg, Germany
Happy FreeBSD user since 4.0
Andra moi ennepe, Mousa, ...


More information about the freebsd-questions mailing list