Numbering!

Just a shot question...

how to make 1,2,3,...999

into the form of

001,002,003....999
(3 digits)
Thanks....

in korn shell, there is a built in utility call typeset for force the leading zero. e.g. this script

#!/bin/ksh
typeset -Z3 var=1
while [ $var -lt 1000 ]
do
echo ${var}
var=`expr $var + 1`
done
#end script

How about in SCO UNIX...?
is there still a typeset command?

i type "man typeset" it said not found

The typeset command will only work in that fashion in the Korn shell (ksh, from AT&T). You may have it installed in /usr/bin, or /bin. If not, you can install it. bash (the Bourne Again SHell) has a typeset command builtin, and pdksh (Public Domain Korn SHell) has it as well, but neither support the -Z option to typeset.

If you want to install (actually talk your admin into installing), check out:

You want the ksh93 package. You'll probably need the INIT package first, though.

Also, you do what you want, you can send the variable into a loop, adding "0"'s until there's enough. Although this is not nearly as good a way as above, it will be portable - especially for systems without David Korn's ksh installed.

korn shell is compatible across the unix families. make sure you run the "typeset" command in the korn shell by issuing "ksh" command at command prompt.

another option, you can put this line at the most top of the shell script:
#!/path/to/ksh

if you cannot find the man page from the unix machine then look for it from the internet. there are tens or more of man page on typeset available.

it is possible to have any other alternative method to do the number formating for what i needed?

"typeset" is built into ksh and is documented on the ksh man page which you can display with "man ksh".

"man while" wouldn't display anything either but I hope you're not afraid to use "while" loops.

Doing this without "typeset" is a chore. You need to count the characters in the variable and prepend the appropriate number of zeros.

I can't really post any sample code since I can't be sure which subset of unix tools that you're willing to use.

well.....if i have a file with 10k line...
i want to rename each line in recursive mode...(while loop)?!
form 000,001...999,000,001.....999....etc....

Must i do something like this :

echo $number+`echo original | cut -c4-` >> newfile 

this line by line method will take me one day to complete....
can someone suggest a better way?

I would go with:

#! /usr/bin/ksh
typeset -Z3 n=0
while read line ; do
      print -r - "${n}${line#???}"
      ((n=n+1))
      ((n>999)) && n=0
done
exit 0
#! /usr/bin/ksh
for file in *
do
	typeset -Z3 n=0
	while read line 
	do
		print -r - "${n}${echo $line | cut -c4-}"
		n=`expr $n +1`
		if [ $n -eq 998 ]
		then
			n=0
		fi
	done
	exit 0
done

THis will just gimme forzen but nothing else....

can ano tell me the problem yy?