Sponsored Content
Full Discussion: Match real numbers in AWK
Top Forums Shell Programming and Scripting Match real numbers in AWK Post 302417454 by cold_Que on Thursday 29th of April 2010 04:50:01 PM
Old 04-29-2010
Match real numbers in AWK

I am looking for a better way to match real numbers within a specified tolerance range. My current code is as follows:

Code:
      if ($1 !~ /^CASE/) for(i=1;i in G;i++) if (G[i] >= $5-1  && G[i] <= $5+1)
         { print $1,$4,$5,J[i],G[i] }
           else { print $1,"NO MATCH" }

where $5 and G[i] are real numbers e.g. "12.456" and "11.543". Right now the code prints out several numbers within the range of 1+ 12.456 and 1-12.456.

Is there a better way of accomplishing this? I would like to get the closest number without manually having to adjust the tolerance range of 1.

Thanks
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

match numbers (awk)

i would like to enter (user input) a bunch of numbers seperated by space: 10 15 20 25 and use awk to print out any lines in a file that have matching numbers so output is: 22 44 66 55 (10) 77 (20) (numbers 10 and 20 matched for example) is this possible in awk . im using gawk for... (5 Replies)
Discussion started by: tanku
5 Replies

2. Shell Programming and Scripting

How to Compare Floating point / real numbers

Hai, Can you please guide me, to compare the floating point numbers. Eg. If then echo "value1 is grater " fi This code is not working properly when i excuted with floating values or real numbers (13 Replies)
Discussion started by: padarthy
13 Replies

3. Shell Programming and Scripting

how to compare big real numbers

Hi everyone, I need to compare 2 big Floating/Real numbers in a script. After the comparission it is showing worng values in my script. echo "Enter value1" read value1 echo "Enter value2" read value2 Result=`echo "if($value1 > $value2) 1" | bc` if ; then echo "$value1 is... (4 Replies)
Discussion started by: padarthy
4 Replies

4. Shell Programming and Scripting

match range of different numbers by AWK

if the column1 and 2 in both files has same key (for example "a" and "a1") compare each first key value(a1 of a) of input2 (for example 1-4 or 65-69 not 70-100 or 44-40 etc) with all the values in input1. if the range of first key value in input2 is outof range in input1 values named it as out... (54 Replies)
Discussion started by: repinementer
54 Replies

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

6. Shell Programming and Scripting

Complex match of numbers between 2 files awk script

Hello to all, I hope some awk guru could help me. I have 2 input files: File1: Is the complete database File2: Contains some numbers which I want to compare File1: "NUMBERKEY","SERVICENAME","PARAMETERNAME","PARAMETERVALUE","ALTERNATENUMBERKEY"... (9 Replies)
Discussion started by: Ophiuchus
9 Replies

7. Shell Programming and Scripting

awk : match only the pattern string , not letters or numbers after that.

Hi Experts, I am finding difficulty to get exact match: file OPERATING_SYSTEM=HP-UX LOOPBACK_ADDRESS=127.0.0.1 INTERFACE_NAME="lan3" IP_ADDRESS="10.53.52.241" SUBNET_MASK="255.255.255.192" BROADCAST_ADDRESS="" INTERFACE_STATE="" DHCP_ENABLE=0 INTERFACE_NAME="lan3:1"... (6 Replies)
Discussion started by: rveri
6 Replies

8. Shell Programming and Scripting

Match on a range of numbers

Hi, I'm trying to match a filename that could be called anything from vout001 to vout252 and was trying to do a small test but I'm not getting the result I thought I would.. Can some one tell me what I'm doing wrong? *****@********>echo $mynumber ... (4 Replies)
Discussion started by: Jazmania
4 Replies

9. Shell Programming and Scripting

awk to update file based on partial match in field1 and exact match in field2

I am trying to create a cronjob that will run on startup that will look at a list.txt file to see if there is a later version of a database using database.txt as the source. The matching lines are written to output. $1 in database.txt will be in list.txt as a partial match. $2 of database.txt... (2 Replies)
Discussion started by: cmccabe
2 Replies

10. Shell Programming and Scripting

awk to print match or non-match and select fields/patterns for non-matches

In the awk below I am trying to output those lines that Match between file1 and file2, those Missing in file1, and those missing in file2. Using each $1,$2,$4,$5 value as a key to match on, that is if those 4 fields are found in both files the match, but if those 4 fields are not found then missing... (0 Replies)
Discussion started by: cmccabe
0 Replies
GSHHS_DP(1gmt)						       Generic Mapping Tools						    GSHHS_DP(1gmt)

NAME
gshhs_dp - Line reduction using the Douglas-Peucker algorithm SYNOPSIS
gshhs_dp input.b tolerance output.b [-v] DESCRIPTION
gshhs_dp reads the binary coastline (GSHHS) or political boundary or river (WDBII) files and and reduces the complexity of the line by applying the Douglas-Peucker algorithm. It automatically handles byte-swabbing between different architectures. input.b GSHHS or WDBII binary data file as distributed with the GSHHS data supplement. Any of the 5 standard resolutions (full, high, intermediate, low, crude) can be used. tolerance tolerance is maximum mismatch in km. The larger the value the more reduction will take place. output.b The reducted data set. OPTIONS
-v Reports progress and statistics while running. EXAMPLES
To simplify the full GSHHS data set with a custom tolerance of 2 km, try gshhs_dp gshhs_f.b 2 gshhs_2km.b REFERENCES
Douglas, D. H., and T. K. Peucker, Algorithms for the reduction of the number of points required to represent a digitized line of its cari- cature, Can. Cartogr., 10, 112-122, 1973. AUTHOR
This implementation of the D-P algorithm has been kindly provided by Dr. Gary J. Robinson, Environmental Systems Science Centre, University of Reading, Reading, UK (gazza@mail.nerc-essc.ac.uk); his subroutine forms the basis for this program. SEE ALSO
GMT(1), gshhs(1), gshhstograss(1) GMT 4.5.7 15 Jul 2011 GSHHS_DP(1gmt)
All times are GMT -4. The time now is 06:06 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy