title: Is it possible to sort a file by part of a line?
body: <p>I am writing shell scripts and I have a file of students and their information (inputFile.txt):</p>
  
  <pre><code>Bonerake:Nicole:1011:410-111-0500:CS:09-12-1985
  Fugett:Brandon:8188:410-111-0020:Biology:06-29-1982
  Bozick:Julia:0333:410-111-0900:English:01-18-1984
  Freeman:Andrew:7747:410-111-0060:Business:03-14-1988
  Carroll:Sandra:4044:410-111-0000:History:12-19-1987
  Everett:Terry:8666:410-111-0100:CS:01-24-1986
  Boyer:Dennie:2212:410-111-0080:Math:08-02-1983
  </code></pre>
  
  <p>I am supposed to sort based on what part of the information the user entered (ie first name, last name, etc.). I am able to do this for last name because it is the first in each line. However, I cannot seem to progress onto any other piece of information. This is what I have tried for sorting by first name, and nothing happens:</p>
  
  <pre><code>sortStudents(){
  echo -e "Which information would you like to sort students by?"
  echo -e "\t1) Last Name"
  echo -e "\t2) First Name"
  echo -e "\t3) Student ID"
  echo -e "\t4) Phone Number"
  echo -e "\t5) Major"
  echo -e "\t6) Birthday"
  echo -e "\t*** Input choice: \c"
  read choice
  
  case "$choice" in
      1) sort inputFile.txt -o inputFile.txt ;;
      2) cut -d: -f2 inputFile.txt | sort inputFile.txt -o inputFile.txt ;;
  esac
  
  return $TRUE
  }
  </code></pre>
  
  <p>I used <code>-f2</code> because I think that that means go to the second field separated by deliminators. I've searched and searched; tried multiple different <code>cut</code> and <code>sed</code> and <code>grep</code> commands, but I cannot seem to find the one with the correct options that I need. Any help will be very much appreciated. Thank you.</p>