Increment a floating number in ksh


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Increment a floating number in ksh
# 1  
Old 09-15-2010
Increment a floating number in ksh

Hi !

How to increment a varibale in ksh. [ something like this : 5.2.102]

Code:
#!/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
+ VAL=0.0.1
+ + bc
+ echo 5.2.103 + 0.0.1
syntax error on line 1, teletype
RELEASE_NUM=
+ echo




NOTE: My intention is to increment like below.

5.2.103 + 0.0.1 = 5.2.104

Last edited by dashok.83; 09-15-2010 at 08:06 AM..
# 2  
Old 09-15-2010
5.2.103 and 0.0.1 are not valid floating numbers.
# 3  
Old 09-15-2010
Yep. Anyways I figured it out..

Code:
#!/bin/ksh


. ./set.properties


echo $RELEASE_NUM | tr -dc '.' | wc -c | read a
a=`echo $a + 1 | bc`
echo $RELEASE_NUM | cut -d "." -f$a | read VAL
echo $RELEASE_NUM |sed "s#$VAL##g" | read REL
VAL=`echo $VAL + 1 | bc`
RELEASE_NUM="$REL$VAL"
echo "RELEASE_NUM=$RELEASE_NUM" > ./set.properties



speedy:/ashok/scripts>cat set.properties

RELEASE_NUM=5.2.3.107

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Convert floating point to a number

Hello Guys, I have a floating point number 1.14475E+15 I want to convert this number in to full number (Integer or Big integer). I tried couple of functions it did not work. When I use INT=${FLOAT/.*} I am getting value as 1. I don't want a truncated value #!/bin/bash #... (9 Replies)
Discussion started by: skatpally
9 Replies

2. UNIX for Dummies Questions & Answers

Bash Floating Number Variables Comparision

I am trying to compare the floating number variables but i am receiving an error, can you please help what is wrong. Thank you. #!/bin/bash var1=100.25 var2=100.25 if (( $var1 == $var2 )); then echo "Matching" else echo "Not Matching" fi Error: ./number.sh: line... (6 Replies)
Discussion started by: Ariean
6 Replies

3. Shell Programming and Scripting

Rounding off to the nearest floating number

I have a number, which I want to convert into the nearest floating number upto two places after the decimal point. E.g. 1.2346 will become 1.23 but 1.2356 will become 1.24 . Similarly 0.009 will be 0.01 and 0.001 will be 0.00 or 0.0 (not 0, wnat to keep the decimal... (1 Reply)
Discussion started by: hbar
1 Replies

4. Shell Programming and Scripting

Need to increment number in data file

Hello, I have an Excel spreadsheet with the following data: Refntns3_1 char 30 Ref H77 nt codon 1 Reference H77 Nucleotide Codon 1 -- Codns3_1 char 30 Obs Nucleotides codon 1 Observed Nucleotides Codon 1 ... (2 Replies)
Discussion started by: deneuve01
2 Replies

5. Shell Programming and Scripting

[BASH] Regex for floating point number

Hey again, I have a basic regex that tests if a number is a float. Thank you. (5 Replies)
Discussion started by: whyte_rhyno
5 Replies

6. Shell Programming and Scripting

problem with floating point number loops

Hey, I guess I am just to stupid and am not seeing the "wood for the trees", but I am always getting strange errors. I want to create a mesh with coordinates like: x y z 3.1 3.0 0.75 0 0 1 3.1 2.9 0.75 0 0 1 3.1 2.8 0.75 0 0 1 3.1 2.7 0.75 0 0 1 3.0 ... (10 Replies)
Discussion started by: ergy1983
10 Replies

7. UNIX for Dummies Questions & Answers

count the number of occurance and increment

Hi, I am trying to count the number of occurance of a specific value in a column and increment the variable in the second column accordingly. I have very little information about Unix. As an example, 21 1 32 1 32 2 45 1 56 1 56 2 56 3 73 1 82 1 Thanks, Natasha (2 Replies)
Discussion started by: natasha
2 Replies

8. Shell Programming and Scripting

floating point number problem

Hello folks I Hope everyone is fine. I am calculating number of bytes calculation from apache web log. awk '{ sum += $10 } END { print sum }' /var/httpd/log/mydomain.log 7.45557e+09 it show above number, what should i do it sow number like 7455, i mean if after decimal point above 5 it... (5 Replies)
Discussion started by: learnbash
5 Replies

9. Shell Programming and Scripting

using bc with floating point number in files

Hi, I' using bash and I would like to use "bc" to compute the ratio of of two numbers and assign the ratio to a variable. The numbers are in a file, e.g. 196.304492 615.348986 Any idea how to do it? N.B. I cannot change the file to have 196.304492 / 615.348986 as the file is produced by... (14 Replies)
Discussion started by: f_o_555
14 Replies

10. Shell Programming and Scripting

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... (5 Replies)
Discussion started by: steiner
5 Replies
Login or Register to Ask a Question