title: awk/bash remove lines with an unique id and keep the lines that has the max/min value in a column under the same ID
body: <p>If we have the following input and would like to firstly, detect if the cpd_number ($2) is unique in the file, remove the whole row.  In this case, the line with "cpd-6666666" should be removed.<br>
  Secondly, if there are multiple lines kept under the same "cpd_number",  only prints out the two lines which has the max and min "log_ratio" ($17). </p>
  
  <pre><code>targetID,cpd_number,Cell_assay_id,Cell_alt_assay_id,Cell_type_desc,Cell_Operator,Cell_result_value,Cell_unit_value,assay_id,alt_assay_id,type_desc,operator,result_value,unit_value,Ratio_operator,Ratio,log_ratio,Cell_experiment_date,experiment_date,Cell_discipline,discipline
  49,cpd-7788990,1212,2323, IC50 ,,100,uM,1334,1331,Ki,,10,uM,,10,-1,12/6/2006 0:00,2/16/2007 0:00,Cell,Enzyme
  49,cpd-7788990,5555,6666, IC50 ,&gt;,150,uM,1334,1331,Ki,,10,uM,&gt;,15,-1.176091259,12/6/2006 0:00,2/16/2007 0:00,Cell,Enzyme
  49,cpd-7788990,8888,9999, IC50 ,,200,uM,1334,1331,Ki,,10,uM,,20,-1.301029996,12/6/2006 0:00,2/16/2007 0:00,Cell,Enzyme
  49,cpd-6666666,8888,9999, IC50 ,,400,uM,1334,1331,Ki,,10,uM,,40,-1.602059991,12/6/2006 0:00,2/16/2007 0:00,Cell,Enzyme
  </code></pre>
  
  <p>The ideal output should be </p>
  
  <pre><code>targetID,cpd_number,Cell_assay_id,Cell_alt_assay_id,Cell_type_desc,Cell_Operator,Cell_result_value,Cell_unit_value,assay_id,alt_assay_id,type_desc,operator,result_value,unit_value,Ratio_operator,Ratio,log_ratio,Cell_experiment_date,experiment_date,Cell_discipline,discipline
  49,cpd-7788990,1212,2323, IC50 ,,100,uM,1334,1331,Ki,,10,uM,,10,-1,12/6/2006 0:00,2/16/2007 0:00,Cell,Enzyme
  49,cpd-7788990,8888,9999, IC50 ,,200,uM,1334,1331,Ki,,10,uM,,20,-1.301029996,12/6/2006 0:00,2/16/2007 0:00,Cell,Enzyme
  </code></pre>
  
  <p>I was trying to use awk count function but it doesn't seem to work quite well.  Could any guru kindly give some comments? Thanks!</p>