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)?
> 
> 
> 
> --------------------------------------------------------------------
> http://www.lug.org.uk                   http://www.linuxportal.co.uk
> http://www.linuxjob.co.uk               http://www.linuxshop.co.uk
> --------------------------------------------------------------------
> 
> 
> 
> --------------------------------------------------------------------
> http://www.lug.org.uk                   http://www.linuxportal.co.uk
> http://www.linuxjob.co.uk               http://www.linuxshop.co.uk
> --------------------------------------------------------------------
> 

------------------------------------------------------------------------------
Paul Millar                            yo-yo, n. :
Particle Physics Theory Group              Something that is occasionally
Department of Physics and Astronomy        up but normally down.
University of Glasgow,                     (see also Computer)
Glasgow G12 8QQ,                                       [EMAIL PROTECTED]
Scotland                                               +44 (0)141 330 4717
------------------------------------------------------------------------------

--------------------------------------------------------------------
http://www.lug.org.uk                   http://www.linuxportal.co.uk
http://www.linuxjob.co.uk               http://www.linuxshop.co.uk
--------------------------------------------------------------------

Reply via email to