The UNIX and Linux Forums  


Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Problem in division rochitsharma UNIX for Dummies Questions & Answers 9 11-25-2008 10:17 PM
Round with division command vanloonmichel Shell Programming and Scripting 13 02-15-2007 09:32 AM
Cannot adjust division jav_v Filesystems, Disks and Memory 1 08-20-2002 09:50 AM
Floating Point Division gsatch Shell Programming and Scripting 1 07-25-2002 05:03 PM
division problem inquirer Shell Programming and Scripting 3 04-02-2002 11:03 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 04-16-2008
Dastard Dastard is offline
Registered User
  
 

Join Date: Jul 2006
Posts: 47
Arrow Floating Division in Linux

Hi everyone , have a great day
given below is the excerpt of code

HTML Code:
k=`grep -i success /var/seamless/spool/tdr/ERS_$date1$time1* | wc -l`;
l=`grep -i fail /var/seamless/spool/tdr/ERS_$date1$time1* | wc -l`;
m=`grep -i entertain /var/seamless/spool/tdr/ERS_$date1$time1* | wc -l`;
n=$(($k+$l))
o=$(($m/$n))
echo $k   $l   $m   $o
no $m is smaller then $n , hence $o will be something less then zero , but above given code doesn echo exact value of o ( should be something like 0.08766..) but it only echos 0
how can i get over this problem
Regards and thanks in anticipation
  #2 (permalink)  
Old 04-16-2008
jim mcnamara jim mcnamara is online now Forum Staff  
...@...
  
 

Join Date: Feb 2004
Location: NM
Posts: 5,800
shell uses integer arithmetic.

use bc or awk

Code:
echo "1.14 3.97" | awk '{print $1/$2}'
# if you need 20 deimals of precision try this:
echo "1.14 / 3.97" | bc -l

  #3 (permalink)  
Old 04-16-2008
Dastard Dastard is offline
Registered User
  
 

Join Date: Jul 2006
Posts: 47
Arrow

Thanks , for your help
one last thing , i have this kinda text in my file

9
2
3
2
1
4
8
0
5
7
9
6




9
2
3
2
1
8
8
2
0
9
3
7




9
2
3
2
1
8
8
2
0
9
3
7




9
2
3
2
2
4
1
4
6
7
0
0




9
2
3
2
2
4
1
4
6
7
0
0




9
2
3
2
1
4
5
6
6
1
0
6


is it possible that i can arrange it something like
923214566106
92321.......
92321...
.......
and so one
i would be very much obliged
  #4 (permalink)  
Old 04-16-2008
vgersh99's Avatar
vgersh99 vgersh99 is online now Forum Staff  
Moderator
  
 

Join Date: Feb 2005
Location: Boston, MA
Posts: 5,131

Code:
nawk -v RS='' -v OFS='' '$1=$1' myFile.txt

Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 06:18 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0