FAQ Search Today's Posts Mark Forums Read
» Video Reviews

» Linux Archive

Linux-archive is a website aiming to archive linux email lists and to make them easily accessible for linux users/developers.


» Sponsor

» Partners

» Sponsor

Go Back   Linux Archive > CentOS > CentOS

 
 
LinkBack Thread Tools
 
Old 07-10-2008, 12:30 AM
"Stephen John Smoogen"
 
Default Shell Script Question

On Wed, Jul 9, 2008 at 6:22 PM, Joseph L. Casale
<JCasale@activenetwerx.com> wrote:
> What's the simplest way to increment the number 0000 up by one until some other 4 digit number while
> preserving leading zero's until the 1000's has a digit other than 0?
>

Your homework done in a snap!

for (i=0; i<1000;i++); do
printf "%04d
" i
done


> Thanks!
> jlc
> _______________________________________________
> CentOS mailing list
> CentOS@centos.org
> http://lists.centos.org/mailman/listinfo/centos
>



--
Stephen J Smoogen. -- BSD/GNU/Linux
How far that little candle throws his beams! So shines a good deed
in a naughty world. = Shakespeare. "The Merchant of Venice"
_______________________________________________
CentOS mailing list
CentOS@centos.org
http://lists.centos.org/mailman/listinfo/centos
 
Old 07-10-2008, 12:37 AM
"Joseph L. Casale"
 
Default Shell Script Question

>Your homework done in a snap!

Lol, nah, not homework :P
I don't know what I was thinking, long day. OTH, I never seq could do this as well!

Thanks!
jlc
_______________________________________________
CentOS mailing list
CentOS@centos.org
http://lists.centos.org/mailman/listinfo/centos
 
Old 07-10-2008, 12:51 AM
Stephen Harris
 
Default Shell Script Question

> What's the simplest way to increment the number 0000 up by one until some other 4 digit number while
> preserving leading zero's until the 1000's has a digit other than 0?

Lots of answers, depending on the shell. I like this version for ksh:

typeset -Z4 a=-1
while (( a++ < 1000 ))
do
print $a
done

Not enough use is made of typeset :-)

--

rgds
Stephen
_______________________________________________
CentOS mailing list
CentOS@centos.org
http://lists.centos.org/mailman/listinfo/centos
 
Old 07-10-2008, 01:06 AM
"Les Bell"
 
Default Shell Script Question

"Joseph L. Casale" <JCasale@activenetwerx.com> wrote:

>>
What's the simplest way to increment the number 0000 up by one until some
other 4 digit number while
preserving leading zero's until the 1000's has a digit other than 0?
<<

Easy:

$ seq -f %04g 0000 9999

Best,

--- Les Bell, RHCE, CISSP
[http://www.lesbell.com.au]
Tel: +61 2 9451 1144
FreeWorldDialup: 800909


_______________________________________________
CentOS mailing list
CentOS@centos.org
http://lists.centos.org/mailman/listinfo/centos
 

Thread Tools




All times are GMT. The time now is 09:58 PM.

VBulletin, Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright 2007 - 2008, www.linux-archive.org