Adding Leading Zero in Bash
Francisco Borges
f.borges at rug.nl
Mon Oct 23 14:38:44 UTC 2006
? On Sun, Oct 22, 2006 at 01:23PM +0200, Wander Boessenkool wrote:
> On 10/22/06, OOzy Pal <oozypal at gmail.com> wrote:
> > Ok, but I don't know number before hand, I mean that I might come a
> > cross 15. Then what would happend am I gona get 015.
> >
> > I would like to add zero when the number is between 0-9 and ignors the
> > zero for number >9
>
> You could use printf formatting: printf %02d $VAR
I just sent an email talking about seq, but, indeed, if the case at hand
is just formating, i.e. he is not generating the number sequence and is
just getting it. Then printf is indeed the right solution.
(I'm sending this because I in another email, jokingly, told the OP to
ignore the other emails... and you already had already sent a proper
solution to it).
Cheers,
--
Francisco
More information about the ubuntu-users
mailing list