floating point variables korn shell


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting floating point variables korn shell
# 1  
Old 06-13-2010
floating point variables korn shell

Hi I'm not using Korn93 but want to use floating point variable.
Is there any solution to do that ?

thx for help.

---------- Post updated at 02:28 PM ---------- Previous update was at 12:38 PM ----------

I have the following peace of code:
Code:
for n in `cat log.January.1.array`
do
       (( number=`print $n | awk -F\; '{print $1}'` ))
      (( filesSize=$filesSize+$number ))
done
 
print "Files size equals : $filesSize"
   
   
(( nrOfIterations=$filesSize/200000 ))
print "Estimated iterations number is: $nrOfIterations"


if (( nrOfIterations>0 ));
then
      (( nrOfIterations=$nrOfIterations+1 ))
      print "Real iterations number is: $nrOfIterations"
      print
fi

Problem is how to distinguish value round this value to sections : ?
1.1-1.5 this should be equal to 1
1.6-1.9 this should be equal to 2

thx for help

---------- Post updated at 02:53 PM ---------- Previous update was at 02:28 PM ----------

I solved it.
Solution below :

Code:
for n in `cat log.January.1.array`
do
       (( number=`print $n | awk -F\; '{print $1}'` ))
      (( filesSize=$filesSize+$number ))
done
 
print "Files size equals : $filesSize"
   
   
(( nrOfIterations=$filesSize/200000 ))
print "Estimated iterations number is: $nrOfIterations"


if (( nrOfIterations=0 ));
then
      (( nrOfIterations=$nrOfIterations+1 ))
      print "Real iterations number is: $nrOfIterations"
      print
else
      (( nrOfIterations=$nrOfIterations+1 ))
      print "Real iterations number is: $nrOfIterations"
      print
fi

# 2  
Old 06-13-2010
Exactly what shell are you using?
# 3  
Old 06-13-2010
I don't know exactly.
How can I read this info in solaris ?
# 4  
Old 06-13-2010
If you are on Solaris, you are probably using a custom version of ksh88. In this case you will have to use the bc utility to perform floating point arithmetic.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Comparison of floating point values in shell

Hi Everyone , Need a simple code here , I Have a number in a variable say $a=145.67 . This value changes everytime loop begins . I need to print a specific message as shown below when the above variable lies in a specific range i.e. 1.if $a lies within 100 and 200 , it should display... (2 Replies)
Discussion started by: robert89
2 Replies

2. Shell Programming and Scripting

'*' vs. '@' in Korn Shell Array Variables

In order to use the shellcurses functions described at: Shell Curses function library I am learning about ksh, which has arrays. My trusty Kochan & Wood book says that for any Korn Shell array AR : ${AR } expands to all the defined array elements, and ${#AR } expands to the number... (3 Replies)
Discussion started by: Clovis_Sangrail
3 Replies

3. Shell Programming and Scripting

Floating Point Numbers in c shell!

I have started using bash but this script which I am working on it, is in c chell. So here is my simple problem: set x = 0.4124\0.234 echo $x 0.4124.0.234 Same operation in Bash gives me correct result in my terminal. So there is something with my c shell that is causing this behaviour.... (8 Replies)
Discussion started by: dixits
8 Replies

4. Programming

Floating Point

Anyone help me i cant found the error of floating point if needed, i added the code complete #include <stdio.h> #include <string.h> #include <stdlib.h> #include <ctype.h> typedef struct { int hh; int mm; int ss; char nom; int punt; }cancion; typedef struct... (9 Replies)
Discussion started by: Slasho
9 Replies

5. Shell Programming and Scripting

How to compare floating point numbers in shell script?

How can we compare 2 floating point numbers in SHELL script? (11 Replies)
Discussion started by: dearanik
11 Replies

6. Shell Programming and Scripting

HELP: compare floating point variables??

Hi All, I got this script that pulls the Amps value from our RPC's , I basiclly want to compare the valued with a "limit" value -- if the numbers match or are greater than the definded value ...do something. My problem is I cant seem to figure out how to compare floating points... here is... (1 Reply)
Discussion started by: zeekblack
1 Replies

7. Linux

Floating point exception !!!

Hi, I have linux fedora 4 ver., 2.6 kernal. And qmail & mysql & samba servers are already configured on this server. When I try to install any package like squidguard ,dansguardian,webmin,rsnapshots with command rpm -ivh . It is giving error as “Floating point exception" Snap View is... (3 Replies)
Discussion started by: ssk01
3 Replies

8. Shell Programming and Scripting

floating point shell variable

I have a two files >cat file1 jjjjj 10.345 6.673 ppp 9.000 5.883 >cat file2 mmm 80 10 jjjjj 10.305 6.873 ppp 9.000 5.883 I am reading file 1 line by line , and look for the string jjjj and then read the line in file 2 with jjjj I want to get the... (5 Replies)
Discussion started by: jojan
5 Replies

9. Shell Programming and Scripting

floating point addition

hi, :) I have a file like this 10.456 123.567 456.876 234.987 ........ ....... What i want to do is ia have to add all those numbers and put the result in some other file. Any help pls. cheers RRK (8 Replies)
Discussion started by: ravi raj kumar
8 Replies

10. Shell Programming and Scripting

Variables Naming in Korn Shell

Hi every body, I want to know what is the different between the following: $VAR1 ${VAR2} "${VAR3}" Are they equivalent? Thanks in advance (1 Reply)
Discussion started by: aldowsary
1 Replies
Login or Register to Ask a Question