How compare decimal values?

Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How compare decimal values?
# 1  
Old 11-13-2013
How compare decimal values?

I have 2 files say tp1.txt and tp2.txt having following data

cat tp1.txt

cat tp2.txt

i want to compare the values on 2nd field of both the file, if value of first tp1.txt is greater than value of tp2.txt it should print "ok" and if if value of first tp1.txt is smaller than value of tp2.txt it should print "Not ok"

Please help me in this...
Thanks in advance.

Last edited by Franklin52; 11-13-2013 at 10:39 AM.. Reason: Fixed code tags
# 2  
Old 11-13-2013
Is there any unique field in both file or you need to compare line by line ?
# 3  
Old 11-13-2013
i want to compare data only line by line for 2nd field having decimal values.
# 4  
Old 11-13-2013
 awk -F"," 'NR==FNR{a[NR]=$2;next}
{printf (a[FNR] > $2) ? "OK\n" : "NOT OK \n" }' File1 FIle2

Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to compare decimal values in bash?

Hi, I am facing some error while doing the comparision between 2 decimal values in bash. Pl help me out. I have tried using below scripts. But its giving me error. 1)amt=12.3 opn_amt=12.5 var=$(awk 'BEGIN{ print "'$amt'"<"'$opn_amt'" }') if ;then echo "correct" else echo "Wrong"... (3 Replies)
Discussion started by: Siba Tripathy
3 Replies

2. Shell Programming and Scripting

Rounding off decimal values

Hi Friends, This is my last post for today. My input file is chr1 100 200 chr1 123 300 chr1 300 400 chr1 420 520 chr10 132344343 132348674 When I try using this command awk '{v=($3+$2)/2; print $0"\t"v}' 1 This is my output chr1 100 200 150 chr1 123 300 211.5 (2 Replies)
Discussion started by: jacobs.smith
2 Replies

3. Shell Programming and Scripting

bin bash decimal compare

I need decimal comparing with if. Check if apache version is less than 2.2.17. I tried this and not working. #!/bin/bash apachever=`/usr/local/apache/bin/httpd -v | head -1 | awk '{print $3}' |cut -d/ -f 2` if ]; then echo "Apache version less than 2.2.17" else ... (7 Replies)
Discussion started by: anil510
7 Replies

4. UNIX for Dummies Questions & Answers

compare decimal and integer values in if in bash shell

i need to do camparisions like the below. For the case when first=10 and second=9.9 the scripts displays process failed. I need to be able to convert the values to integer before doing the comparision. Like 9.9 should be rounded over to 10 before doing comparision. Please advice how can... (3 Replies)
Discussion started by: nehagupta
3 Replies

5. Shell Programming and Scripting

How to get decimal values ?

Hi All, In my script I've written like this- c=$( expr 100 / 3);echo $c The output coming is 33. but I want to see 33.33, decimal values too. How to get that? Thanks, Naresh (3 Replies)
Discussion started by: NARESH1302
3 Replies

6. Shell Programming and Scripting

Compare float value with single decimal

#!/bin/bash filter_file=/export/home/alvin/test.txt range1_count=0 range2_count=0 categorized(){ value=$1 if # range 5.1 to 10.0 then range1_count=`expr $range1+ 1` elif # range 5.1 to 15.00 then range2_count=`expr $range2+ 1` fi } #read txt file which contain lines of... (8 Replies)
Discussion started by: alvin0618
8 Replies

7. UNIX for Advanced & Expert Users

Converting Binary decimal coded values to Ascii Values

Hi All, Is there any command which can convert binary decimal coded values to ascii values... i have bcd values like below оооооооооооо0о-- -v - Pls suggest a way to convert this. Thanks, Deepti.Gaur (3 Replies)
Discussion started by: gaur.deepti
3 Replies

8. Shell Programming and Scripting

Compare integer value with decimal

Hi all, I have a issue... Is it possible to compare integer value with decimal value. If it is not possible,then how can i compare 2 decimal values in born shell.thanks! (3 Replies)
Discussion started by: MARY76
3 Replies

9. Shell Programming and Scripting

compare decimal numbers

Hi anyone, i need to compare two decimal numbers i thought that it could be do it with if but... :( So, i'm writing in csh and i really apreciate if anyone can help me if ( $ppl_kn <= $ppl_wb ) then echo "############# KNdiscount model has the lowest perplexity" set... (5 Replies)
Discussion started by: tmxps
5 Replies
Login or Register to Ask a Question

Featured Tech Videos