[Gllug] Poor scripting?!

John Edwards john at cornerstonelinux.co.uk
Tue Mar 11 16:23:44 UTC 2008


On Tue, Mar 11, 2008 at 04:01:54PM +0000, Richard Huxton wrote:
> John Edwards wrote:
>> On Tue, Mar 11, 2008 at 02:41:16PM +0000, Henrik Morsing wrote:
>>> Hi, I've had a look and help from the #gllug folks (thanks!), does
>>> this look like it would do the same job, called as 'rename
>>> s/cerprod/$CRMDB/ s/medprod/$CRMDB /cerillion'?
>> <snip> 
>> 
>> Is there any reason you aren't using Perl's own rename program?
>> 
>> find . -iname "*pattern*" -print0 | xargs -r0 rename 's/pattern/replacement/g'
> 
> Nice.

It would of course need the -type and -maxdepth options added to find,
and the full path to the Perl supplied rename (/usr/bin/prename on
Debian) in case there are some other rename scripts in the search
path.


>> Of course you may have too many directories for rename to process as
>> arguments. It certain works with several thousand.
> 
> Ah, xargs --max-args should handle that though.

But won't that leave some directories unchanged as xargs with truncate
the list of directories that find supplies?

Anyway a test run with 'rename -n' seemed to handle 300,000+ entries.


> Hmm - not sure about the /g on the pattern, although I see that was 
> present in the original question. I'd worry about accidentally matching 
> directory namse.

Yeah, that was just a touch of habit from the fingers. It's not needed
and as you say could be dangerous if the pattern was present in any
parent directory.


I've still no idea why the original was run twice. Maybe the
directories were being created as it ran or the original command
failed occasionally. Neither of which are good reasons to run this
twice of course.


-- 
#---------------------------------------------------------#
|    John Edwards   Email: john at cornerstonelinux.co.uk    |
#---------------------------------------------------------#
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 196 bytes
Desc: Digital signature
URL: <http://mailman.lug.org.uk/pipermail/gllug/attachments/20080311/e544a1af/attachment.pgp>
-------------- next part --------------
-- 
Gllug mailing list  -  Gllug at gllug.org.uk
http://lists.gllug.org.uk/mailman/listinfo/gllug


More information about the GLLUG mailing list