I have a file which stores a number between 1~9999999. However, if the number is less than 7 digits, I need to fill it with 0s. e.g. if the number is 14, then I need to make it be 0000014. Any hints?
Ygor, sorry for misleading. What I mean is, the value in file1 is unknown, or better say it changes everyday. If file1 contains 14, we need to add 5 preceding 0s to 0000014. If file1 contains 8682, we need to add 3 0s to 0008682.
My approach is to add seven 0s to the number in file1 which yields [0000000<1~7 digit number>], and cut the right hand side 7 digits to [<(7-no. of digits in file1) 0s><number in file1>].
I tried your method printf "%07d\n" `cat file1` but it doesn't work. Thanks a lot!
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.