Linux print numbers with leading zeros

Some times while we are handling numbers it may require to print them leading zeros or with equal width.

Following is the example to print a number with leading zeros.

Print a number with width 5  

$ printf “%.5d” “21”

Output: 00021

To print sequence of numbers with leading zeros

$ seq -w 1 10

Output:

01
02
03
04
05
06
07
08
09
10

-Sany

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s