Padding expr output
Hi all, I am usiung expr in a shell script and need to pad it's output to always be 3 characters. An example will explain thing better: % expr 007 + 1 Output is 8 I need the output to be 008 I checked the expr man page, but nothing there solves my problem. Anyone out there got one? Thanks in advance - Would you like to receive faxes to your personal email address? You can with mBox. Visit http://www.mbox.com.au/fax To Unsubscribe: send mail to [EMAIL PROTECTED] with unsubscribe freebsd-questions in the body of the message
Re: Padding expr output
# [EMAIL PROTECTED] / 2002-12-23 10:57:19 +1100: Hi all, I am usiung expr in a shell script and need to pad it's output to always be 3 characters. An example will explain thing better: % expr 007 + 1 Output is 8 I need the output to be 008 printf(8) zero-padded integer and octal, respectively: roman@freepuppy ~ 1029:0 printf %03d\n $(expr 8 + 1) 009 roman@freepuppy ~ 1030:0 printf %#o\n $(expr 8 + 1) 011 roman@freepuppy ~ 1031:0 -- If you cc me or remove the list(s) completely I'll most likely ignore your message.see http://www.eyrie.org./~eagle/faqs/questions.html To Unsubscribe: send mail to [EMAIL PROTECTED] with unsubscribe freebsd-questions in the body of the message
Re: Padding expr output
# [EMAIL PROTECTED] / 2002-12-23 01:12:22 +0100: # [EMAIL PROTECTED] / 2002-12-23 10:57:19 +1100: Hi all, I am usiung expr in a shell script and need to pad it's output to always be 3 characters. An example will explain thing better: % expr 007 + 1 Output is 8 I need the output to be 008 printf(8) printf(1), of course. -- If you cc me or remove the list(s) completely I'll most likely ignore your message.see http://www.eyrie.org./~eagle/faqs/questions.html To Unsubscribe: send mail to [EMAIL PROTECTED] with unsubscribe freebsd-questions in the body of the message
Re: Padding expr output
on 12/22/02 3:57 PM, BSD Freak [EMAIL PROTECTED] wrote: Hi all, I am usiung expr in a shell script and need to pad it's output to always be 3 characters. An example will explain thing better: % expr 007 + 1 Output is 8 I need the output to be 008 I checked the expr man page, but nothing there solves my problem. Anyone out there got one? Don't use expr to do the formatting. Use some sprintf-like capability in some scripting language that supports full functionality from the command-line. I think both awk and perl have that capability in some form. (Maybe someone else can be more specific.) Kurt Bigler Thanks in advance To Unsubscribe: send mail to [EMAIL PROTECTED] with unsubscribe freebsd-questions in the body of the message
Re: Padding expr output
Kurt Bigler wrote: on 12/22/02 3:57 PM, BSD Freak [EMAIL PROTECTED] wrote: Hi all, I am usiung expr in a shell script and need to pad it's output to always be 3 characters. An example will explain thing better: % expr 007 + 1 Output is 8 I need the output to be 008 I checked the expr man page, but nothing there solves my problem. Anyone out there got one? Don't use expr to do the formatting. Use some sprintf-like capability in some scripting language that supports full functionality from the command-line. I think both awk and perl have that capability in some form. (Maybe someone else can be more specific.) Kurt Bigler Thanks in advance To Unsubscribe: send mail to [EMAIL PROTECTED] with unsubscribe freebsd-questions in the body of the message In bash: i=8 while [ ${#i} -lt 3 ] do i=0${i} done echo $i To Unsubscribe: send mail to [EMAIL PROTECTED] with unsubscribe freebsd-questions in the body of the message