Awk: Length of column number

半世苍凉 提交于 2019-12-14 04:07:06

问题


I have a (maybe) silly question.

My data: File 1

1234.34  a 1235.34 d
3456.23  b 3457.23 e
2325.89  c 2327.89 f 

I want something like

awk '{if($1==$3) print $4}'

But of course if I do this, it will print nothing. So I want to modify the "precision" of $3 (in this case)

in the sense that when awk read $3 it finds this:

124
345
232

then it must be a way to do this, but I don't know it.

awk '{if($1==(three digits precision $3)) print $4}'

Help?


回答1:


You could calculate the difference of the two values:

awk '$1 - $3 < 0.01 || $3 - $1 < 0.01 {print $4}' file


来源:https://stackoverflow.com/questions/22934069/awk-length-of-column-number

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!