How to grep rows that have value less than 0.2 in a specific column?

谁都会走 提交于 2020-01-22 12:15:52

问题


  ID RT      EZ    Z0      Z1      Z2    RHO     PHE 

 1889  UN    NA  1.0000  0.0000  0.0000  0.8765  -1  
 1890  UN    NA  1.0000  0.0000  0.0000  0.4567  -1  
 1891  UN    NA  1.0000  0.0000  0.0000  0.0012  -1  
 1892  UN    NA  1.0000  0.0000  0.0000  0.1011  -1  

I would like to grep all the IDs that have column 'RHO' with value less than 0.2, and the other columns are included for the selected rows.


回答1:


Use awk directly by saying awk '$field < value':

$ awk '$7<0.2' file
 1891  UN    NA  1.0000  0.0000  0.0000  0.0012  -1  
 1892  UN    NA  1.0000  0.0000  0.0000  0.1011  -1  

As RHO is the column 7, it checks that field.

In case you just want to print a specific column, say awk '$field < value {print $another_field}'. For the ID:

$ awk '$7<0.2 {print $1}' file
1891
1892


来源:https://stackoverflow.com/questions/22556923/how-to-grep-rows-that-have-value-less-than-0-2-in-a-specific-column

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