LinuxQuestions.org
Register a domain and help support LQ
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
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!

Notices


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

Rep: Reputation: 15
Padding a number


Hi,

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, 06:11 AM   #2
Tinkster
Moderator
 
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 23,066
Blog Entries: 11

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

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


Reply


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 04:05 PM
Date format lost padding OldGaf Programming 2 05-01-2008 08:25 PM
Prevent compiler padding structures out to WORD boundaries guestgulkan Programming 3 12-05-2006 04:57 PM
string padding and replacement functions George2 Programming 4 11-19-2006 03: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 10:36 AM


All times are GMT -5. The time now is 05:32 PM.

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