Thread: Incrementing parts of ten digits number by parts

Enjoy an ad free experience by logging in. Not a member yet? Register.
1. Incrementing parts of ten digits number by parts

I have number in file which contains date and serial number:
2013101000.

The last two digits are serial number (00). So maximum of serial number is 100.

After reaching 100 it becomes 00 with incrementing 10 which is day with max 31.

after reaching 31 it becomes 00 and increments 10 which is month with maximum 12.

so basically when I run code it rewrites 10 digits with above conditions... File is in path...so i check file check his number and then increment it and rewtite file with new number. My problem is that my code gives me 1 only and rewrite file with 1 . Help me to fix my code please thanks.

So example:
cat file
2013113098

sh my_code
cat file
2013113099

sh my_code
cat file
2013113100

sh my_code
cat file
2013113101

then I sh my_code 100 times
cat file
2013120100

MY piece of code is

Code:
n= sort /Users/Manu/1/kuku.txt | tail -1
#n=2013080805
#echo "\${n:0:4} \${n:4:2} \${n:6:2} \${n:8:2}"

fourthoct=\${n:0:4}
thirdoct=\${n:4:2}
secondoct=\${n:6:2}
firstoct=\${n:8:2}
echo \$n

if [ \$((++firstoct)) -eq 101 ]
then
firstoct=00
if [ \$((++secondoct)) -eq 32 ]
then

secondoct=0
if [ \$((++thirdoct)) -eq 13 ]
then
thirdoct=0
((++fourthoct))
fi
fi
fi

echo \$fourthoct\$thirdoct\$secondoct\$firstoct

2. And your question/point is? ...

Please describe what the purpose of this "algorithm" is, and what you want to accomplish. Your description is not rigorous enough to make any substantial comments about.

Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•