Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: pad numbers
- X-seq: zsh-users 13455
- From: Phil Pennock <zsh-workers+phil.pennock@xxxxxxxxxxxx>
- To: fREW Schmidt <frioux@xxxxxxxxx>
- Subject: Re: pad numbers
- Date: Sat, 15 Nov 2008 11:04:25 -0800
- Cc: zsh-users@xxxxxxxxxx
- Domainkey-signature: a=rsa-sha1; q=dns; c=nofws; s=d200807; d=spodhuis.org; h=Received:Date:From:To:Cc:Subject:Message-ID:Mail-Followup-To:References:MIME-Version:Content-Type:Content-Disposition:In-Reply-To; b=Rdz+thXLPvif8Y+Tpw8TQmPXTKoWN1AbPyqzWajDvAONLz9IG34i6Mo1DFlGQER56fK8O/9Ak5qZ/BRlSP8QW8Udgdq+pQFfbIgdsb75BTXAn+XsDoi2Dp2Ju8qVimrbn2jUQgzdkuyBwYN015+t59U0GgvDcxRjOmm/vOE9NJY=;
- In-reply-to: <fb3648c60811151036l32c43737k66b5faf57a142e9b@xxxxxxxxxxxxxx>
- Mail-followup-to: fREW Schmidt <frioux@xxxxxxxxx>, zsh-users@xxxxxxxxxx
- Mailing-list: contact zsh-users-help@xxxxxxxxxx; run by ezmlm
- References: <fb3648c60811151008m68a8125jbe0db623500516ee@xxxxxxxxxxxxxx> <20081115183337.GF3238@xxxxxxxxx> <fb3648c60811151036l32c43737k66b5faf57a142e9b@xxxxxxxxxxxxxx>
On 2008-11-15 at 12:36 -0600, fREW Schmidt wrote:
> Ah shoot, I forgot to mention that the files are actually named like this
> 01 - foo bar.baz
If you want to specify the length more manually than the simple method:
% mkdir T && cd T
% touch '01 - Foo' '02 - Bar' '03 - Baz' '100 - Fred' '2000 - Long'
naive:
% zmv '([[:digit:]]##)(*)' '${(l:3::0:)1}$2'
% ls
000 - Long 001 - Foo 002 - Bar 003 - Baz 100 - Fred
Note that this has truncated the 2000 entry because I have explicitly
specified that $1 should be fit within a field three characters wide,
left-padded with digit 0. See zshexpn(1), Parameter Expansion Flags.
Recreating the original files, then:
% zmv '([[:digit:]]|[[:digit:]][[:digit:]])([^[:digit:]]*)' '${(l:3::0:)1}$2'
% ls
001 - Foo 002 - Bar 003 - Baz 100 - Fred 2000 - Long
You might prefer [0-9] to [[:digit:]].
Perhaps you prefer the zmv -W approach. ;-)
-Phil
Messages sorted by:
Reverse Date,
Date,
Thread,
Author