title: Bash: sort text file by last field value
body: <p>I have a text file containing ~300k rows. Each row has a varying number of comma-delimited fields, the last of which is guaranteed numerical. I want to sort the file by this last numerical field. I can't do:</p>
  
  <pre><code>sort -t, -n -k 2 file.in &gt; file.out
  </code></pre>
  
  <p>as the number of fields in each row is not constant. I think sed, awk maybe the answer, but not sure how. E.g: </p>
  
  <pre><code>awk -F, '{print $NF}' file.in
  </code></pre>
  
  <p>gives me the last column value, but how to use this to sort the file?</p>