Depending on which distro you are using, there are a few alterations to your script which will help. I have not had time to actually test this, so use with caution: 

#!/bin/bash

# This will loop through the argumented txt file, and create the users as necessary.
# You will need to run this as root, so be very careful. Start with a small user file.

line=1 # Initiate variable for counting.
count="$(cat $1 | wc -l)"  # This counts the number of lines, which will decide how many times the loop itterates.
until [ $line -gt $count ]
do
    # Begin by grabbing one line (user to be added)
    newuser="$(head -$line $1 | tail -1)" # This gets just the one line at a time.
    # Now split the data as needed according to your original post:
    fname="$(echo $newuser | awk '{print $2}')" # AWK to get First Name
    lname="$(echo $newuser | awk '{print $1}')" # AWK to get Last Name
    minit="$(echo $newuser | awk '{print $3}')" # AWK to get middle initial
    group="$(echo $newuser | awk '{print $4}')" # AWK to get Group
    # Now create the random username.
    initial="$(echo $fname | head -c 1)"
    random="$(shuf -i 1-9 -z -n 3)"
    shortname="$(echo $lname | head -c 3)"
    username="$initial$shortname$random" # This will output exactly what is needed, although your example does not stick to what you want...
    # Now create the user.
    # Does group exist?
    if egrep -i "^$group" /etc/group
    then
        true # This is not the best way to do this, but my toddler kept me up all night...
    else
        groupadd $group
    fi
    if [ ! -d "/home/$group" ]
    then
        mkdir -m 774 /home/$group
    fi
    # Make the home dir.
    mkdir -m 777 /home/$group/$username

    # Actual useradd command
    useradd -g $group -d /home/$group/$username -p $(openssl passwd -1 $username) $username
    if [ $? = 0 ]
    then
       echo "User $username has been successfully created."
       chown $username:$group /home/$group/$username
       chmod 755 /home/$group/$username
    else
       echo "Something went wrong, user $username was NOT created."
       rm /home/$group/$username
    fi

    # Now generate line for txt output file
    output="$lname $fname $(id -u $username) $username"
    printf "\n$output" &gt;&gt;./output.txt
    # Now increment the counter
    line="$((line +1))"
done

exit


Like I said in the beginning, I haven't tested this properly, because I don't really want to create a bunch of users :-) so be careful - test the useradd line first. The rest should be solid.

Bash script- Create usernames and passwords from txt file and store in group?
I read these two posts and now I am more confused.

Do heavier objects fall faster?

Don&#39;t heavier objects actually fall faster because they exert their own gravity?

I was going to ask: if mass is an objects tendency to resist acceleration then why do two objects of different masses fall to the Earth at the same acceleration?

Then I read those posts and it seems that even though it is very small, the more massive object falls faster. Okay I understand, both objects attract each other.

If two cars of different masses collide doesn't the car with less mass accelerate more even though both cars received the same Force. Then that implies you need more force to accelerate a large mass than to accelerate a small mass. Because that is how I see it, the Moon attracts the Earth with the same Force as the Earth attracts the Moon but the Earth accelerates less due to its larger mass.

So then how is mass an object's tendency to resist acceleration? I am aware of $F_1 = F_2 = GMm/r^2$. So should we not really be able to see the difference in acceleration when dropping a massive object?
