Help answer threads with 0 replies.
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!


  Search this Thread
Old 07-07-2009, 05:05 AM   #1
Registered: Jan 2006
Location: Sydney
Distribution: RHEL
Posts: 72

Rep: Reputation: 15
Padding a number


Is there a function (or a way) in Linux to pad a number with specific number of characters.

For example, the number 5 to be converted to 005, and 13 to 013.

Thanks in advance.
Old 07-07-2009, 05:11 AM   #2
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910
printf "%.03d\n" 5
printf "%.03d\n" 13
Old 07-07-2009, 05:33 AM   #3
Registered: Apr 2009
Location: ~
Distribution: RHEL, Fedora
Posts: 381

Rep: Reputation: 58
echo 5 | awk '{printf("%.03d\n", $1)}'


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Firefox toolbars have too much padding in xubuntu 8.04 XFCE mrtwice Linux - Software 0 09-04-2008 03:05 PM
Date format lost padding OldGaf Programming 2 05-01-2008 07:25 PM
Prevent compiler padding structures out to WORD boundaries guestgulkan Programming 3 12-05-2006 03:57 PM
string padding and replacement functions George2 Programming 4 11-19-2006 02:09 AM
why there is a need for minor number and major number for monitor/keyboard in pc? tripathi Solaris / OpenSolaris 1 11-07-2003 09:36 AM > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 04:37 AM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration