0

I have a file with 11 Columns of data deliminated by a space between each. For each line in column 2, I need to find the closest value in column 9. So below it would take the first entry in column 2 (0.01) and find the closest value in column 9 (0.009 in line 3).

File layout:

x 0.01 x x x x x x 0.002 x x
x 0.034 x x x x x x 0.0045 x x
x 0.002 x x x x x x 0.009 z z
x 0.002 x x x x x x 0.0021 x x
x 0.015 x x x x x x 0.0031 x x

Current code:

awk '{
if (sqrt(($2)^2-($9)^2)<0.0001)
   print "Particle ID  "$1" is within 2D of wall"
}' filename

Which I think has two problems:

1) This doesn't compare every permutation, just for each line in the columns

2) It only checks if they are within a certain range, not the closest.

Desired output would be a new file which is something like

x 0.01 x x x x x x 0.009 z z

and so on for all the other lines

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.