Increminting a number

Hi

im creating lots of log files, Im writing a script to number them and scp them to a remote server,
the files need to be called 0001.log 0002.log etc etc

in my script I made a counter variable

$counter=00001

I tried adding a number to the variable like this
$counter=`echo "$counter + 1" | bc`

but this gives me 2 not 0002

i tried with perl also $counter++

does anyone know a simple way to imrement but keep the leding 0's ??

Thanks

Try this:

#! /usr/bin/ksh
typeset -Z4 number=0
while ((number<10)); do
    ((number=number+1))
    echo $number
done
exit 0

I keep a list of all RFC's on my workstation for some idle reading, and use a script to diplay a topic for the number I supply. The format they're in is: rfc####.txt, where the extra spaces are padded by "0"'s. I came up with this simple little routine to pad the left side of the number with zero's until I get a total of 4 characters:

...
numcheck=$((`echo $num | wc -c` - 1))
until [ "$numcheck" = "4" ]; do
num="0${num}"
numcheck=$((`echo $num | wc -c` - 1))
done
rcfname=rfc${num}.txt
...

This may not be the best way to do it, but it works for my needs... Please post back if you want more help with this.

HTH

Wow, I like Perderabo's much better.... time to re-write rfc.sh! :stuck_out_tongue:

Thanks guys, my script works fine now

its was this command that I needed form your script

typeset -Z4 number=0

:smiley:

Livinfree, What exactly do you refer to as RFC's ??

Silly newbie question I guess :smiley:

request for comment

I presume he means.

Click here for a list of rfc's.