0

Here I am trying to find the closest value of a variable in 1st column; then want to print the corresponding value in the 2nd column.

for ex:- the file a.txt contains:-(2 columns)

2 8 2.5 10 3 30 3.5 50

If t1=2.75;

after running my code:-

r_t1=more $a.txt |awk '{if($1=='$t1') print $2}'

It prints nothing as 2.75 is not there in any of the rows in 1st column.

But in my work I want $t1 to match with the closest value of a row in the 1st column of "a.txt".

Means if t1=2.75; then it should print "30" (as 2.75 is close to 3; hence print the corresponding row of 2nd column)

How to do it???? Kindly help

0 Answers0