[Gllug] perl script

Nick Mailer nickm at positive-internet.com
Wed Aug 21 18:23:22 UTC 2002


On Wednesday 21 August 2002 6:09 pm, Philippe Rousselot wrote:
> Hi,
>
> I need to modify the title of several files and would like to run a script
> I need to invert letter 1 with letter 4 and letter 2 with letter 5
>
> 01_02_03_04.jpeg becomes 02_01_03_04.jpeg
>
>
> #!/bin/bash
> for i in *jpeg
> do
> rename ???????
> done
>
>
>
> Your help would be greatly appreciated.
>

This Perl I've knocked up (cos I don't like shell) should work (presuming you 
start in the CWD, otherwise make the path explicit in the rename/opendir):


opendir (DIR, '.');
foreach ( grep {/\.jpeg$/} readdir DIR ) {
    /^(.)(.)(.)(.)(.)(.*)$/;
    rename ($_, "$4$5$3$1$2$6");
}


Nick Mailer
The Positive Internet Company Ltd.

-- 
Gllug mailing list  -  Gllug at linux.co.uk
http://list.ftech.net/mailman/listinfo/gllug




More information about the GLLUG mailing list