title: Extracting of the text data using bash utilities
body: <p>I have non-trivial task to extract some relevant data from the big CSV logs which looks like</p>
  
  <pre><code>Frame #,Residue,Internal,van der Waals,Electrostatic,Polar Solvation,Non-Polar Solv.,TOTAL
  1,1,119.745,0.356,-132.009,-95.618,1.7886312,-105.7373688
  1,2,106.093,-3.835,-182.473,40.582,0.7132608,-38.9197392
  1,3,21.228,-1.744,-38.026,-7.707,1.1189664,-25.1300336
  1,4,-5.717,-4.721,-30.38,-4.839,0.406512,-45.250488
  1,5,70.846,-4.127,-53.317,-2.534,0.7808472,11.6488472
  ...
  2,1,119.745,0.356,-132.009,-95.618,1.7886312,-105.7373688
  2,2,106.093,-3.835,-182.473,40.582,0.7132608,-38.9197392
  2,3,21.228,-1.744,-38.026,-7.707,1.1189664,-25.1300336
  2,4,-5.717,-4.721,-30.38,-4.839,0.406512,-45.250488
  2,5,70.846,-4.127,-53.317,-2.534,0.7808472,11.6488472
  ...
  n,1,119.745,0.356,-132.009,-95.618,1.7886312,-105.7373688
  n,2,106.093,-3.835,-182.473,40.582,0.7132608,-38.9197392
  n,3,21.228,-1.744,-38.026,-7.707,1.1189664,-25.1300336
  n,4,-5.717,-4.721,-30.38,-4.839,0.406512,-45.250488
  n,5,70.846,-4.127,-53.317,-2.534,0.7808472,11.6488472
  </code></pre>
  
  <p>here I'd like to chose specified one value from 2nd column (#residue) and write evolution(function of #snapshot number column) of its last column (#total energy) according to the 1st column (#frame number). In other words I need to 1) sort all of the data in accordance with the 2nd column first): i.e to select each string where the number in second column equal to specified value (i.e n=27)</p>
  
  <pre><code>#Frame, #Residue
  
  1,27, ... , # last column value which is interested for me!
  2,27, ... , # last column value which is interested for me!
  3,27, ... , # last column value which is interested for me!
  3,27, ... , # last column value which is interested for me!
  </code></pre>
  
  <p>and than extract corresponding values of its last column so the resululting log will have onlu 3 columns:</p>
  
  <pre><code>#Frame, #Residue, # Total energy
  
  1,27, # last column value which is interested for me!
  2,27, # last column value which is interested for me!
  3,27, # last column value which is interested for me!
  3,27, # last column value which is interested for me!
  </code></pre>
  
  <p>Will be thankful for any realization using awk and sed!</p>
  
  <p>Thanks!</p>
  
  <p>Gleb</p>