[comp.unix.questions] Renaming groups of files

jmm@calmasd.GE.COM (James Moore) (06/04/87)

What's the best way to go about renaming groups of files
like:

a.a
a.b
a.c
a.d

To:

b.a
b.b
b.c
b.d

Or the same thing without the dot?  We'd also like to be
able to add a suffix and a prefix to any group of files.

Thanks,

James

lm@cottage.WISC.EDU (Larry McVoy) (06/05/87)

In article <2271@calmasd.GE.COM> jmm@calmasd.UUCP (James Moore) writes:
>What's the best way to go about renaming groups of files

Boy, do I have a deal for you:  if what you want is to do stuff like

% mov *.c *.c++ 

or 

% mv a.* b.*

or anything similar, I have written just such a tool.  It uses the regex
stuff that was posted a while ago and forks off a bunch of mv's to do the
work (a little slow, I know, but reasonable).  It was inspired by something
called "mved.sh" that was too slow to be really useful.  I'll mail you the 
source, if I get any other requests, I'll post to net.sources (or whatever
it's called these days).


Larry McVoy 	        lm@cottage.wisc.edu  or  uwvax!mcvoy

mlandau@Diamond.BBN.COM (Matt Landau) (06/05/87)

In article <2271@calmasd.GE.COM> jmm@calmasd.UUCP (James Moore) writes:
>What's the best way to go about renaming groups of files

There's a program called "rename" by Gilles Chartrand (whose email address
I do not have) that does exactly this.  It was posted to net.sources or
mod.sources quite a while ago.  If there's sufficient interest, I can 
repost it (after I return from Usenix).  It's nicer than some of the
alternatives I've seen suggested in that it doesn't require forking copies
of "mv" to do the renaming.  It's less nice than some because "mv" will
move things across filesystems, whereas the rename() system call used directly 
will not.
-- 
 Matt Landau			    "Lead me not into temptation...
 mlandau@diamond.bbn.com	     		I can find it myself."

woods@hao.UCAR.EDU (Greg Woods) (06/05/87)

In article <2271@calmasd.GE.COM> jmm@calmasd.UUCP (James Moore) writes:
>What's the best way to go about renaming groups of files
>like:
>
>a.a a.b a.c a.d
>
>To:
>
>b.a b.b b.c b.d

  You can take advantage of the dot being there if you are a C-shell user
(there might be a similar trick in the Bourne shell, I don't know).

foreach f (a.*)
mv $f b.$f:e
end

The :e modifier on a variable substitution takes the "extension", i.e. the
part after the last dot.

--Greg
-- 
UUCP: {hplabs, seismo, nbires, noao}!hao!woods
CSNET: woods@ncar.csnet  ARPA: woods%ncar@CSNET-RELAY.ARPA
INTERNET: woods@hao.ucar.edu

ken@rochester.UUCP (06/06/87)

I like to use sed in a shell stream, thus:

	ls a.* | sed 's/a\.\(.*\)/mv & b\.\1/' | sh

with other variations for renaming suffixes, middles, etc.

Yes, it is cryptic, but a really quick solution. A nice thing is
you can leave out the | sh the first time and then say !! | sh
when you see the commands generated are right. In csh, that is.

	Ken