Padding numbers in filenames

Rick Delaney rick-h4KjNK7Mzas at public.gmane.org
Tue Feb 27 02:35:49 UTC 2007


On Feb 26 2007, William O'Higgins Witteman wrote:
> 
> rename -n "s/(\d)\.png/000$1png/" *
> 
> This would only catch the first 9 files, but I no that I had the right
> method.

That's because you're only matching a single digit.  It will "catch"
more files but do the wrong thing.

    rename -n 's/(\d+)/sprintf("%04d", $1)/e' *.png

or without the wasteful brackets

    rename -n 's/\d+/sprintf("%04d", $&)/e' *.png

> I can certainly whip up a quick program in Python or Perl (I could

??  rename *is* Perl.

-- 
Rick Delaney
rick-h4KjNK7Mzas at public.gmane.org
--
The Toronto Linux Users Group.      Meetings: http://gtalug.org/
TLUG requests: Linux topics, No HTML, wrap text below 80 columns
How to UNSUBSCRIBE: http://gtalug.org/wiki/Mailing_lists





More information about the Legacy mailing list