Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: Feature request: ${(l[-3][0])var} to do left padding *without truncation*
On Sat, Aug 3, 2024 at 7:22 AM Stephane Chazelas <stephane@xxxxxxxxxxxx> wrote:
>
> $ set -o extendedglob
> $ a=1-12-123-1234-12345
> $ echo ${a//(#m)<->/${(l[3][0])MATCH}}
> 001-012-123-234-345
>
> Numbers are "l"eft padded to a length of 3 with 0s, but also
> truncated to 3 digits when longer. It's often not desired.
In the current dev version / forthcoming release (whenever that happens):
echo ${a//(#m)<->/${|printf -v REPLY "%03d" "$MATCH"}}
Messages sorted by:
Reverse Date,
Date,
Thread,
Author