On Wed, 24 Nov 2004 18:38:23 +0000, Proinnsias Breathnach
<proinnsias at linux.ie> wrote:
> On Wed, Nov 24, 2004 at 06:21:50PM -0000, Tanney, Austin wrote:
> > The naming system is as follows (this is an example filename that actually exists)
> > RDCR011_D09_2004-03-30.scf
> >
> > In this case.. I want to change the name to
> > xRDCR011_D09.scf
> >
> > Basically.. I want to remove the characters "_2004-03-30"
> > Now.. these are not set characters and change for each file.
> > I'm happy enough to run this as 4 processes.. i.e., one for each file type.
> >
> Okay - are the filenames all the same length ?
> if so - cut may be your friend here !
Or one could do a regexp pattern match using sed to rub out the date:
for x in *scf; do mv $x $(echo $x | sed -e
"s/_[0-9]\{4\}\-[0-9]\{2\}\-[0-9]\{2\}\././g" -); done
for 5000 files, on an aged PII-450 this took just shy of 3 minutes
Or _much_ better, use Brian Brazil's method (I saw his mail while
I was writing this response). On the same system, his method takes a
MUCH nicer 16 seconds to rename 5000 files, better than an order of
magnitude faster :-)
Proinnsias's solution:
>> for i in *
> do
> export $start =`( echo $i | cut -c1-11)`
> export $end = `(echo $i | cut -c22-25)`
>> mv $i ${start}${end}
>> done
renamed the 5000 files in a time of 2minutes and 11 seconds, as he says:
> It's not going to be the fastest - but it'll work :)
Well, it's not the slowest either... though it's a bit less general
than my cut at the problem (I half-heartedly console myself :-).
Brian's method means that the whole collection of 185000 would take
about 10 minutes to
process (based on the unlikely assumption the files are being renamed
on an ancient PII). A nice illustration of the benefit of using the
right tool for the job
Michael
Maintained by the ILUG website team. The aim of Linux.ie is to
support and help commercial and private users of Linux in Ireland. You can
display ILUG news in your own webpages, read backend
information to find out how. Networking services kindly provided by HEAnet, server kindly donated by
Dell. Linux is a trademark of Linus Torvalds,
used with permission. No penguins were harmed in the production or maintenance
of this highly praised website. Looking for the
Indian Linux Users' Group? Try here. If you've read all this and aren't a lawyer: you should be!