Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

linux

grep

cut

  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.

like image 232
user3446084 Avatar asked Mar 21 '14 11:03

user3446084


People also ask

How to use grep in unix?

To search multiple files with the grep command, insert the filenames you want to search, separated with a space character. The terminal prints the name of every file that contains the matching lines, and the actual lines that include the required string of characters. You can append as many filenames as needed.


1 Answers

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
like image 64
fedorqui 'SO stop harming' Avatar answered Oct 27 '22 13:10

fedorqui 'SO stop harming'