Padding numbers in filenames

William O'Higgins Witteman william.ohiggins-H217xnMUJC0sA/PxXw9srA at public.gmane.org
Tue Feb 27 15:00:01 UTC 2007


On Mon, Feb 26, 2007 at 09:35:49PM -0500, Rick Delaney wrote:
>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.

<slap style="forehead" />  Thank you!  I keep forgetting about greedy
tokens.  I just don't use regexes often enough.

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

Interesting - I've never really used the "e" switch, or seen sprintf in
a regex, but it certainly makes sense.  The fact that everyone suggested
using a formatted print should be a clue for me to get more acquainted
with them.

>??  rename *is* Perl.

That's why I tend to use it before I use a bash loop - I have spent way
more time with Perl then with bash.  Not enough, plainly, but still :-)

Thanks to all.
-- 

yours,

William

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 189 bytes
Desc: Digital signature
URL: <http://gtalug.org/pipermail/legacy/attachments/20070227/47f04224/attachment.sig>


More information about the Legacy mailing list