Numeric calculation in shell scripting


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Numeric calculation in shell scripting
# 15  
Old 04-12-2013
Quote:
Originally Posted by Yoda
In HP-UX, the shells are limited to integer arithmetic.
Except /usr/dt/bin/dtksh:

Code:
$ echo $(( 34. /50 * 100 ))
68

Code:
$ echo $(( .035 / 1862 ))
0.000018796992


Last edited by Scrutinizer; 04-12-2013 at 05:55 PM..
This User Gave Thanks to Scrutinizer For This Post:
# 16  
Old 04-12-2013
Quote:
Originally Posted by Jewel
need help urgent asap!!!
Be patient, we are not on call!

Use -l option that causes an arbitrary-precision math library to be predefined:
Code:
$ echo "  .035 / 1862 " | bc -l
.00001879699248120300

# 17  
Old 04-12-2013
Quote:
Originally Posted by Jewel
by using below code ,not getting floating value which is equals to 0

echo " .035 / 1862 " | bc

need help urgent asap!!!
Everyone at the UNIX and Linux Forums gives their best effort to reply to all questions in a timely manner. For this reason, posting questions with subjects like "Urgent!" or "Emergency" and demanding a fast reply are not permitted in the regular forums.

For members who want a higher visibility to their questions, we suggest you post in the Emergency UNIX and Linux Support Forum. This forum is given a higher priority than our regular forums.

Posting a new question in the Emergency UNIX and Linux Support Forum requires forum Bits. We monitor this forum to help people with emergencies, but we do not not guarantee response time or best answers. However, we will treat your post with a higher priority and give our best efforts to help you.


Thank you.

The UNIX and Linux Forums
# 18  
Old 04-12-2013
Quote:
Originally Posted by Scrutinizer
Except /usr/dt/bin/dtksh:
Good to know about dtksh

But I discovered that it is part of CDE, so dtksh will not be available if CDE is not installed.
# 19  
Old 04-13-2013
Yes that is a good point. In my experience CDE used to be installed by default, so it was there unless the administration team had made a conscious choice to uninstall it / not to install it , but it appears it has become optional in HP-UX 11.31, so there CDE would need to be installed first..

Last edited by Scrutinizer; 04-13-2013 at 05:01 AM..
# 20  
Old 04-16-2013
friend,

this command is working fine on command prompt with using variable. But while i using variable with same code in in script, it doesnot working.

Thanks,
Jewel

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

need help from you all

Last edited by Jewel; 04-16-2013 at 04:38 PM..
# 21  
Old 04-16-2013
You need to make sure the script executes with the same shell as the shell you are using to test it with.. What shell are you using and how do you execute your script?
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to do simple date (time) calculation in shell script?

Hi, I'm looking for a way to do a simple math calc during a shell script as a means of logging how long a particular task takes. For example... STARTTIME=whenever this script starts ./path/to/command.sh >>logfile.log TOTALTIME=<time at this stage of the script after above command... (7 Replies)
Discussion started by: nbsparks
7 Replies

2. Shell Programming and Scripting

Math calculation over shell

Hi I am trying to calculate the rate at which something is happening. I have 2 files- a1 and b1. I want to calculate something like this ((wc -l a1)/(wc -l a1 + wc -l b1))*100 over a loop for different a and b. Is this possible, help me out fellas. Thanks a lot :) (5 Replies)
Discussion started by: jamie_123
5 Replies

3. Shell Programming and Scripting

Modulo calculation in shell script

hi i am writing a progrm to print the even numbers and the code which i am following is as follows #!/usr/bin/bash echo "enter a number a" read a if then echo "the number is even" else echo "the number is odd" fi ~ what is the mistake i am doing ...please tell me (3 Replies)
Discussion started by: harjinder
3 Replies

4. Shell Programming and Scripting

KSH SHELL: problem calculation number of lines inside compressed file

Hi Gurus, I am working with a korn shell script to simplify some operations of calculation number of lines inside compressed file. The called function (inside a cycle) is the following: ######################################### # F.ne: CheckCount #########################################... (3 Replies)
Discussion started by: GERMANICO
3 Replies

5. UNIX for Dummies Questions & Answers

Find and Replace random numeric value with non-numeric value

Can someone tell me how to change the first column in a very large 17k line file from a random 10 digit numeric value to a non numeric value. The format of lines in the file is: 1702938475,SNU022,201004 the first 10 numbers always begin with 170 (6 Replies)
Discussion started by: Bahf1s
6 Replies

6. Shell Programming and Scripting

calculation using awk or shell script in between the numbers

file A E969K D223L E400L E34L file B predicted 3 1 250 251 500 501 1000 The output should be E969K 501 1000 D223L 1 250 E400L 251 500 E34L 1 250 I tried in this way (1 Reply)
Discussion started by: cdfd123
1 Replies

7. Shell Programming and Scripting

Arithmetic calculation on real numbers in Bourne Shell Script

I am begining to learn bourne shell and as a practice I have written a script which when given the purchase price and percentage of discount calculates the savings. I somehow cannot figure out why my script fails to do arthimatic calculation on real numbers. Could anyone look at the script... (5 Replies)
Discussion started by: Tirmazi
5 Replies

8. Shell Programming and Scripting

Need help in shell script to trim numeric values

Hello I am currently working on a shell script which actually needs to pull some file from a server , The filenames will have the extension with date/time stamp , i need to trim that and name it to proper format Example : xyz_20091108_22142365.gzip i need to remove the... (5 Replies)
Discussion started by: ranga27
5 Replies

9. Shell Programming and Scripting

Perl code to differentiate numeric and non-numeric input

Hi All, Is there any code in Perl which can differentiate between numeric and non-numeric input? (11 Replies)
Discussion started by: Raynon
11 Replies

10. Shell Programming and Scripting

difference between AIX shell scripting and Unix shell scripting.

please give the difference between AIX shell scripting and Unix shell scripting. (2 Replies)
Discussion started by: haroonec
2 Replies
Login or Register to Ask a Question