[X-Unix] Re: Help batch renaming files with two "extentions"

Eugene list-themacintoshguy at fsck.net
Thu Mar 24 00:31:28 PST 2005


On Wed, Mar 23, 2005 at 10:47:50PM -0500, Timothy Luoma <lists at tntluoma.com> wrote:
: 
: On Mar 23, 2005, at 8:33 PM, David Haines wrote:
: 
: >I've had success batch-renaming files named according to standard 
: >practice:
: >
: >filename.gif
: >
: >for example.
: >
: >I'm faced with a large number of files named:
: >filename.w01.tif
: >
: >filenmae.w07.tif
: >
: >etc.
: >
: >and need to be able to strip all of them of :   .tif
: >
: >This is certainly beyond my limited-but-slowly-growing shell-scripting
: >abilities.
: 
: First of all, you ought to have Fink and/or DarwinPorts installed, and 
: then you can install GNU Coreutils easily.  Using DP it's a simple
[...]

"basename" is already installed if you have the BSD subsystem package
installed as well.  So no need to install additional packages.

: Once you have coreutils, you'll find you have a whole lot of useful 
: utilities such as 'basename' which would make this dirt simple
: 
: 
: #!/bin/sh
: 
: for FILENAME in *.tif
: do
: 
: 	short=`basename $FILENAME .tif`
: 
: 	mv -iv "$FILENAME" "$short"
: 
: done
: 
: # eof

Or compress it into a single command line:

	$ for a in *.tif; do mv "$a" "`basename "$a" .tif`"


-- 
Eugene
http://www.coxar.pwp.blueyonder.co.uk/


More information about the X-Unix mailing list