Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Add leading zeros to running number

Posted on 2006-04-17
3
Medium Priority
?
1,327 Views
Last Modified: 2013-12-26
Hi everyone,

I need to append leading zeros to a running number.

How should I do it?

I tried this but I keep getting errors.

if [ expr $counter <= 9 ]
     then
        counter1 = "0000"$counter
     else
        if [ expr $counter <= 99 ]
        then
           counter1 = "000"$counter
        else
           if [ expr $counter <= 999 ]
           then
              counter1 = "00"$counter
           else
              if [ expr $counter <= 9999 ]
              then
                 counter1 = "0"$counter
              fi
           fi
        fi
     fi


Is there another way like append "0000" to $counter, then reverse the string and cut the 1st 5 bytes, then reverse the string back again.
0
Comment
Question by:chawtee
  • 2
3 Comments
 

Author Comment

by:chawtee
ID: 16475006
Hi,

I'm running this in unix F-secure SSH.

Thanks!
0
 
LVL 4

Accepted Solution

by:
uniques earned 200 total points
ID: 16475328
if [ $counter -le 9 ]
     then
        counter1="0000"$counter
     else
        if [ $counter -le 99 ]
        then
           counter1="000"$counter
        else
           if [ $counter -le 999 ]
           then
              counter1="00"$counter
           else
              if [ $counter -le 9999 ]
              then
                 counter1="0"$counter
              fi
           fi
        fi
     fi
0
 

Author Comment

by:chawtee
ID: 16475368
Thanks uniques!

The point goes to you!
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction: Finishing the grid – keyboard support for arrow keys to manoeuvre, entering the numbers.  The PreTranslateMessage function is to be used to intercept and respond to keyboard events. Continuing from the fourth article about sudoku. …
Introduction: Dialogs (2) modeless dialog and a worker thread.  Handling data shared between threads.  Recursive functions. Continuing from the tenth article about sudoku.   Last article we worked with a modal dialog to help maintain informat…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Integration Management Part 2
Suggested Courses
Course of the Month14 days, 17 hours left to enroll

577 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question