title: Bash Script Help Needed
body: <p>So I'm working on an assignment and I'm very close to getting it. Just having issues with the last part. Here is the whole problem I guess, just so you know what I'm trying to do -</p>
  <blockquote>
  <p>Write a shell script called make_uid which creates user login names given a file containing the user's full name. Your script needs to read the newusers file, and for each name in the file create a login name which consists of the first character of the users first name, and up to 7 characters of their last name. If the last name is less than seven characters, use the entire last name. If the user only has one name, use whatever is provided as a name (in the newusers file) to generate an 8 character long login name. Note: login names need to be all lower case!</p>
  <p>Once you have created a login name, you need to check the passwd file to make sure that the login name which you just created does not exist. If the name exists, chop off the last character of the name that you created, and add a digit (starting at 1) and check the passwd file again. Repeat this process until you create a unique user login name. Once you have a unique user name, append it to the passwd file, and continue processing the newusers file.</p>
  </blockquote>
  <p>This is my code so far. At this point, it makes a full passwd file with all of the login names. I'm just having trouble with the final step of sorting through the list and editing duplicates accordingly.</p>
  <pre><code>#!/bin/bash
  #Let's make some login names!
  
  declare -a first
  declare -a last
  declare -a password
  file=newusers
  
  first=( $(cat $file | cut -b1 | tr &quot;[:upper:]&quot; &quot;[:lower:]&quot; | tr '\n' ' ') )
  for (( i=0; i&lt;${#first[@]}; i++)); do
    echo ${first[i]} &gt;&gt; temp1
  done
  
  last=( $(cat $file | awk '{print $NF}' $file | cut -b1-7 | tr &quot;[:upper:]&quot; &quot;[:lower:]&quot;))
  for (( i=0; i&lt;${#last[@]}; i++)); do
    echo ${last[i]} &gt;&gt; temp2
  done
  
  paste -d &quot;&quot; temp1 temp2 &gt;&gt; passwd
  sort -o passwd passwd
  more passwd
  rm temp1 temp2
  </code></pre>