On Fri, May 05, 2017 at 08:16:52PM +1000, Mark Trickett wrote:

> > Most rename scripts you'll write are just one or more
> > 's/search/replace/' one-liner statements, but they can be a quite
> > complicated perl script if required.
>
> I need to learn perl, but will do a lot better around other people,

most renames won't need much perl, just regular expression search & replace.



> >     $ rename --version
> >     /usr/bin/rename using File::Rename version 0.20
> >
> > or check 'man rename' - if it mentions perl, it's good.
>
> That reported perl, but the --version option is not supported on the
> rename on this install.

that sounds like the default rename included in the perl package. it
should work but has some problems that are fixed in later versions.

the rename package is only 12 KB in size, so won't use much bandwidth to
download.

it has no dependencies other than perl, either so I could mail it to you if
you want.  or download direct from your nearest debian mirror without
bothering with 'apt-get' (updating the package lists will be tens of
megabytes).  install with 'dpkg -i' (as root, of course).

Package: rename
Version: 0.20-4
Installed-Size: 36
Maintainer: Debian Perl Group <[email protected]>
Architecture: all
Replaces: libfile-rename-perl
Provides: libfile-rename-perl
Depends: perl
Conflicts: libfile-rename-perl
Description-en: Perl extension for renaming multiple files
 This package provides both a perl interface for renaming files
 (File::Rename) and a command line tool 'rename' which is intended to
 replace the version currently supplied by the perl package.
Description-md5: f25bdadb8b97cbf70a4a78c50ca2e8af
Homepage: https://metacpan.org/release/File-Rename
Section: perl
Priority: optional
Filename: pool/main/r/rename/rename_0.20-4_all.deb
Size: 12464
MD5sum: 11987300e5cbab887e2b34692665dc3a
SHA256: 51ed56802ac8f84b588cc9db117469071e7b434cf8544aab2ef1d66c6686a00f


> > but in the meantime, try something like this to start with:
> >
> > #              DD    MM    YYYY   (nnn)
> > rename -n 's/(\d\d)(\d\d)(\d{4})\./$3-$2-$1(000)./;
> >            s/(\d\d)(\d\d)(\d{4})(\(\d{3}\))\./$3-$2-$1$4./;
> >           ' *.jpg
> >
> > the first s/// statement matches and replaces filenames WITHOUT
> > the 3-digit sequence (and adds a sequence of "(000)").  The second
> > matches filenames WITH them.
>
> I think I can start to follow what you are doing, and I need to be
> careful, In typing emails and the like, I am hitting extra keys

the s/// statements above should work with the filenames you listed.

and copy-and-paste the rename command into a terminal should also work,
no need for error-prone typing. that's part of the reason why I used
the '-n' option, so it only does a dry-run and doesn't actually rename
anything.

or paste it into a text file, insert a first line of '#!/bin/sh', and
make it executable with 'chmod +x'. and change *.jpg to "$@" so you can
specify the filenames on the command line. like so:

#!/bin/bash

rename -n 's/(\d\d)(\d\d)(\d{4})\./$3-$2-$1(000)./;
            s/(\d\d)(\d\d)(\d{4})(\(\d{3}\))\./$3-$2-$1$4./;
          ' "$@"


get rid of the '-n' when you've tested it and seen that it will work as
required.

craig

--
craig sanders <[email protected]>
_______________________________________________
luv-main mailing list
[email protected]
https://lists.luv.asn.au/cgi-bin/mailman/listinfo/luv-main

Reply via email to