You can still use the 'groups' command and just use awk with sed to grab only the first (primary group) that it displays. Anyhow, you can play around with that. Instead I used the cut command. The script below will:
1. Display the GID (which I know you are not interested but hey, in case you want to see it)
2. Take the GID and compare that with the /etc/group file to grab the primary group
3. Then displays the Primary Group how you wanted.
As you can see, it's pretty straight forward. If you have any questions, let me know. Have fun!
-twantrd
#!/bin/bash
PASSFILE="/etc/passwd"
GRPFILE="/etc/group"
echo "Enter the username that you want to look up the Primary Group for: "
read input
gid=`grep $input $PASSFILE | cut -d : -f 4`
echo "GID is: $gid"
pri_grp=`grep $gid $GRPFILE | cut -d : -f 1`
echo "Primary Group is: $pri_grp"
exit 0