title: How to apply different sorting methods to different columns in a CSV file in BASH?
body: <p>I have a CSV file like this:</p>
  
  <pre><code>fish,4
  cat,1
  elephant,1
  tree,2
  dog,8
  car,10
  </code></pre>
  
  <p><code>awk -F',' '{print length($1),$0}' file.csv | sort -k1nr | cut -d' ' -f 2-</code> will sort the file by word length, for all words appearing in the first column:</p>
  
  <pre><code>elephant,1
  fish,4
  tree,2
  cat,1
  dog,8
  car,10
  </code></pre>
  
  <p><code>sort -t, -k+2 -n -r file.csv</code> will sort the file from greatest to least according to the number appearing in the second column:</p>
  
  <pre><code>car,10
  dog,8
  fish,4
  tree,2
  elephant,1
  cat,1
  </code></pre>
  
  <p>How can I use these two commands together such that the CSV file is first sorted by word length, according to the words appearing in the first column, then any rows containing words of equal length within the first column are sorted according to the number appearing in the second column from greatest to least. The resulting output would look like this:</p>
  
  <pre><code>elephant,1
  fish,4
  tree,2
  car,10
  dog,8
  cat,1
  </code></pre>
  
  <p>How can these two sorting methods be used together?</p>