Math calculation help


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Math calculation help
# 1  
Old 06-10-2005
Math calculation help

Hi,
I wrote this script
Code:
awk -F"\t" '{if ((($1 == 586) || ($1 == 68030)) && (($2/1024) < 512)) print $0"\t"(512-($2/1024))"\t"(512-($2/1024))/256}' pcs.txt

But I want from the calculation in red to get rid of the decimal part. Like instead of 1.75 to keep only 1.Please somebody tell me what I had to add to my script to do this.

Cheers
# 2  
Old 06-10-2005
Code:
awk -F"\t" '{if ((($1 == 586) || ($1 == 68030)) && (($2/1024) < 512)) print $0"\t"(512-($2/1024))"\t"int((512-($2/1024))/256)}' pcs.txt

# 3  
Old 06-10-2005
I tried it before and it is the same result without it. Also I tried it into parenthesis (int) but also it is not working. I am using SSH secure shell for windows
# 4  
Old 06-10-2005
Quote:
Originally Posted by sickboy
I tried it before and it is the same result without it. Also I tried it into parenthesis (int) but also it is not working. I am using SSH secure shell for windows
Note the placement of the parenthesis int((512-($2/1024))/256)

This works correctly on cygwin, solaris 8,9,10, FC3 and SuSE 9.2 which are the only systems I have immediately to hand.
# 5  
Old 06-11-2005
I didn't notice them before. It's is working.
Thanks a lot
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Math

i have file (my_file.txt) that looks like this: 000000000000010000 000000000000010000 000000000000005000 000000000000005000 000000000000005000 000000000000005000 000000000000005000 000000000000005000 000000000000005000 000000000000005000 all said and one, it should look... (11 Replies)
Discussion started by: lawsongeek
11 Replies

2. UNIX for Dummies Questions & Answers

Linux Math Help

I am struggling with scripting this challenge a friend and I have. You have file1 and its contents is a single number you have file 2 and its contents are a different number you want to add file1 to file2 and have the output be put into file3 (3 Replies)
Discussion started by: minkyboodle
3 Replies

3. 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

4. Shell Programming and Scripting

Need help with AWK math

I am trying to do some math, so that I can compare the average of six numbers to a variable. Here is what it looks like (note that when I divide really big numbers, it isn't a real number): $ tail -n 6 named.stats | awk -F\, '{print$1}' 1141804 1140566 1139429 1134210 1084682 895045... (3 Replies)
Discussion started by: brianjb
3 Replies

5. Shell Programming and Scripting

math calculation for a txt file

Hi All, I have a text file which is only one column. I want to multiply all these values in file1.txt by 0.01 and get the output.txt file1.txt 65 85 90 ... output.txt 0.65 0.85 0.90 ... Thanks. Please use code tags when posting data and code samples! (2 Replies)
Discussion started by: senayasma
2 Replies

6. Shell Programming and Scripting

Script math calculation

Hi Gurus, I'm currently using HP-UX B.11.23. I've a simple calculation script which performs the task below. -> echo "240021344 / 1024 /1024" | bc Output: 228 240021344 is KB value. When I tried to perform the same calculate in Ms Excel, it produces a different result: 228.9021912.... (12 Replies)
Discussion started by: superHonda123
12 Replies

7. Shell Programming and Scripting

math help

$ x=1 $ y=1.5 $ z=$((x*y)) bash: 1.5: syntax error: invalid arithmetic operator (error token is ".5") What's wrong? (2 Replies)
Discussion started by: rockbike
2 Replies

8. Programming

math.h in makefile

Hey all, How do I link the math library in a gnu make makefile? I have tried using -lm with the CFLAGS varibale - flags like -Wall and -ggdb work, but -lm does not. I am running gcc - 4.1.2 on a linux machine. (2 Replies)
Discussion started by: kermit
2 Replies

9. Programming

something about <math.h>

Hi, I got an easy problem for you but really difficult for me 'cause I am pretty new to this field I got header file <math.h> included in my .c file , then I write the code as below: k = sqrt(i); /* both variables k and i are int */ then I cc temp.c it says like this undefined... (4 Replies)
Discussion started by: blf0
4 Replies

10. Programming

math.h not working? o.0

Alright, umm i cant get this to work. im looking at some example and a book i have. when i try to compile my program i get an error message. ld: 0711-317 ERROR: Undefined symbol: .sqrt ld: 0711-345 Use the -bloadmap or -bnoquiet option to obtain more information. I did #include<math.h> after my... (2 Replies)
Discussion started by: primal
2 Replies
Login or Register to Ask a Question