Increment counter in ksh


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Increment counter in ksh
# 1  
Old 08-06-2003
Increment counter in ksh

Hello,

I am making an increment counter in ksh. So i write a number in a temporary file and when I execute my script I read this file and I make +1.

But how can I make this with a number with 6 digits , example
000009 + 1 = 000010
...
....
....
000099 + 1 = 000100

Do anyone know where I can make this ????

PS : I have also use the ltrim function in ksh but the syntaxe was not good. Perhaps I little help for this function.

Thanks a lot....
# 2  
Old 08-06-2003
Try this...
Code:
typeset -Z6 number
number=9
echo $number
((number=number+1))
echo $number
exit 0

These 2 Users Gave Thanks to Perderabo For This Post:
# 3  
Old 08-07-2003
Increment counter

Hello,

Thanks for you little code , it's work funny...

Thanks and bye...
# 4  
Old 12-02-2003
Increment counter in ksh

Hi,

OK and how is it possible if you have to increment on 10 digits.

I tried with typeset -Z10 number.

but doesn't work.

Many thanks for answering.

liliput
# 5  
Old 12-02-2003
What output are you seeing? The code works fine here. Are you sure your are executing in ksh? ie, specifying the shell?

#!/bin/ksh

typeset -Z10 number
number=9
echo $number
((number=number+1))
echo $number
exit 0

Cheers,

Keith
# 6  
Old 12-02-2003
Hi Keith,

Many thaks for answering.

you're right. it works fine.

MAny thanks.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Bash counter increment not working

Hi all, I'm using Bash 4.3.8 on an Ubuntu system, and no matter what I try, incrementing a counter won't work. The simplest example would be something like this: #!/bin/bash myVar=0 myVar=$((myVar++)) echo myVar The variable should be 1, but it's always 0. I've tried every increment... (6 Replies)
Discussion started by: Zel2008
6 Replies

2. Shell Programming and Scripting

Do i miss counter or what

hello this script should show all users and space they used without problem : ls /home >> /root/users.txt cat /root/users.txt | while read line; do space=`du -s /home/$line` echo "$line space is $space" shift done but when i remove pipe ,script run without any output: ls /home... (4 Replies)
Discussion started by: nimafire
4 Replies

3. Shell Programming and Scripting

Comparison of fields then increment a counter reading line by line in a file

Hi, i have a scenario were i should compare a few fields from each line then increment a variable based on that. Example file 989878|8999|Y|0|Y|N|V 989878|8999|Y|0|N|N|V 989878|8999|Y|2344|Y|N|V i have 3 conditions to check and increment a variable on every line condition 1 if ( $3... (4 Replies)
Discussion started by: selvankj
4 Replies

4. UNIX for Dummies Questions & Answers

Pegging counter

Hi Experts, I am in need for some help. My competence level on unix is not at all helping me to resolve this. Please help. My Input for a system command is as under: Counters are getting pegged each hour. I need to have a difference printed rather than pegged counter values. Counter... (2 Replies)
Discussion started by: vanand420
2 Replies

5. Shell Programming and Scripting

Help require with counter

I have this file 1801,A1,2012-12-16 15:59:59.995,id2_3,ab,phoneC2-00,VOE,,,,,,,,,,,,,,, 1802,A1,2012-12-16 15:59:59.995,id2_3,ab=,phoneX1-01,BL,,,,,,,,,,,,,,, 1803,A1,2012-12-16 15:59:59.995,id2_3,ab,phone300,BL,,,,,,,,,,,,,,, 1804,A1,2012-12-16... (4 Replies)
Discussion started by: nikhil jain
4 Replies

6. Shell Programming and Scripting

Counter

if ;then echo "mrnet greater 5000" gzip /var/log/mrnet.log mv /var/log/mrnet.log.gz /var/log/mrnet.log.1.gz if ];then i=1 let i++ mv /var/log/mrnet.log.1.gz /var/log/vieux-logs/mrnet.log.$i.gz else echo "theres no... (1 Reply)
Discussion started by: Froob
1 Replies

7. Shell Programming and Scripting

increment counter as suffix starting with the rightmost digit

Hi, I would like to add a suffix to a file name but maintain the suffix length to 5 digits. For eg, output > 1st_file.00001, 2nd_file.00002...10th_file.00010....100th_file.00100 Can anyone please advise me on how to go about it? Platform: SunOS mps201a 5.9 Generic_118558-39 sun4u... (7 Replies)
Discussion started by: danish0909
7 Replies

8. Shell Programming and Scripting

Increment a floating number in ksh

Hi ! How to increment a varibale in ksh. #!/bin/ksh set -x RELEASE_NUM=5.2.103 VAL=0.0.1 RELEASE_NUM=`echo $RELEASE_NUM + $VAL | bc` echo $RELEASE_NUM The above code is throwing this error. + RELEASE_NUM=5.2.103 (2 Replies)
Discussion started by: dashok.83
2 Replies

9. Shell Programming and Scripting

counter

Hi, I need some help. Shell script counter. i need to add condition to check if counter is more than 10 and longer than 3 hours? it runs every 5 mins. it only check count and send email right now. it runs in cron as below gregcount.ksh gregdb 10 > /tmp/gregcount.out 2> /tmp/gregcount.err ... (1 Reply)
Discussion started by: pega
1 Replies

10. UNIX for Dummies Questions & Answers

counter / increment problem within echo stmt

Simple script trying to increment a counter within an echo statement never gets past 1 - PLEASE HELP! Thanks. ~~~~~~~~~~~ #!/bin/sh stepup() { STEP=`expr $STEP + 1` echo $STEP } # # Initialize variables # STEP=0 echo "Counter Value: `stepup`" echo "Counter Value:... (2 Replies)
Discussion started by: blaze
2 Replies
Login or Register to Ask a Question