dirtdog has asked for the wisdom of the Perl Monks concerning the following question:
Hi Monks, I'm hoping someone can assist with a one-liner. I'm trying to pad a leading zero to a 5 digit time. I'm close, but I'm missing something.
perl -i.bak -pe 's/\<time\>(\d+)\<\/time\>/\<time\>sprintf("%06d",$1)\ +<\/time\>/ if /\<time\>(\d{5})\<\/time\>/' <file>
I'm ending up with the following:
<time>sprintf("%06d",10001)</time>
and I'm expecting this:
<time>010001</time>
any help would be greatly appreciated!
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Using SprintF in S & R
by herveus (Prior) on Jul 11, 2017 at 18:06 UTC | |
by afoken (Chancellor) on Jul 11, 2017 at 20:37 UTC | |
by Laurent_R (Canon) on Jul 11, 2017 at 19:00 UTC | |
by herveus (Prior) on Jul 11, 2017 at 19:25 UTC | |
Re: Using SprintF in S & R
by Anonymous Monk on Jul 11, 2017 at 17:48 UTC | |
by dirtdog (Monk) on Jul 11, 2017 at 18:06 UTC |
Back to
Seekers of Perl Wisdom