![]() |
Zero padding
How can I add zero pad a number based on a variable length so that the length of the number is always the same?
Example: 00004 00023 34243 Always has a length of 5 with zeros added in when necessary Edit: nm i found out how using seq -w anyways, i have another question about %04d . Instead of using 4 for the digits, how could I make 4 be a variable instead? Would %0$(length)d work instead? |
Just a suggestion: when you edit a post after finding a solution, please leave the original material. Other members may be looking for a solution to the same problem. Add your answer and help them out. Then add your new question, or start another thread.
|
use printf %0nd $yourNum where n is the length you want displayed
|
Quote:
I apologize for deleting the original post |
I don't know if there's a log function in bash, but if you know the length of the longest one you could use printf %0${maxlen}d $yourNum.
|
Thanks for the help. Normally I would test it, but I'm borrowing a friend's comp so no Linux. :( Just trying to do the best without
|
| All times are GMT -5. The time now is 4:47 PM. |
Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC