Paul Millar wrote:
> 
> Yep, but if I can add a bug-fix (see the sed R.E.) and a slight
> improvement:
> 
> On Wed, 23 Jan 2002, Gordon Pearce wrote:
> > for i in *; do [ -f $i ] && mv -i $i `echo $i | sed -e 's/htm/shtml'`; done;
> 
> but if any of the files have spaces in their filename, it all becomes
> rather messy :
> 
> for i in *; do
>   [ -f "$i" ] && mv -i "$i" "`echo "$i"|sed -e 's/htm/shtml/'`";
> done
> 
> (this can all be one line, but that wouldn't look so good here)
> 
> You might want to be a bit more specific with your sed, e.g. have
> 's/\.htm$/\.shtml$/' instead. This will only match at the end of the
> filename and also must match the dot too.
> 
> > take note of the apostrophes and backticks!!
> 
> And the many double quotes :)
> 
> Cheers,
> 
> Paul.
> 
> > ----- Original Message -----
> > From: <[EMAIL PROTECTED]>
> > To: <[EMAIL PROTECTED]>
> > Sent: Wednesday, January 23, 2002 5:31 PM
> > Subject: [scottish] Batch renaming of files
> >
> >
> > Is there a simple way of renaming a set of files? I want to merge two
> > directories
> > containing image files and change the names to something systematic like
> > 01.jpg, 02.jpg, etc.
> >
> > When I tried using mv, I get a message saying
> > "When moving multiple files, last parameter must be a directory"
> >
> > Presumably someone's already written a script to do this: any suggestions
> > where I can find one (which will run on Mandrake 8.0)?

Hi,

This all looks very nice - nothing like a random mixture of as many
types of quotes and other obscure symbols on one line to put the newbies
off.

For the people who can't find the ` key on their keyboard, you could
perhaps check out a simple little command/program called "mmv" (multiple
move) which should do the job. It may come as standard with some
distros.

However, I don't think this command (or the solutions people were
quoting) actually answer the question originally posed.

I think the question is we have a directoy structure like

        mydirectory/pictureofme.jpg
        mydirectory/otherpictureofme.jpg
        hisdirectory/wow.jpg
        hisdirectory/lookatthis.jpg

And want to end up with:

        newdir/1.jpg
        newdir/2.jpg
        newdir/3.jpg
        newdir/4.jpg

In answer to the original question, I don't really know of a _simple_
way to do this.

You could try:

# !/bin/bash

mkdir newdir
a=1
for i in mydirectory/* hisdirectory/*; do
        cp "$i" newdir/$a.jpg
        let a=$a+1
done

Look! I managed to do it on more than one line, I must be great since
everyone else only seems to be able to write a single line of code :).

Thanks,

Allan
-- 
Don't argue with a fool. The spectators can't tell the difference.
--------------------------------------------------------------------
http://www.lug.org.uk                   http://www.linuxportal.co.uk
http://www.linuxjob.co.uk               http://www.linuxshop.co.uk
--------------------------------------------------------------------

Reply via email to