This will give you a list of users and gid starting with 4 - modify it for your needs ( sorry it's what I use to write scripts in).
Code:
#!/bin/csh
set allusers="`who -q`"
foreach xx ($allusers)
if ("$xx" == "#") then
exit
else
# find info on user
set mygid=`grep $xx /etc/passwd|awk -F: '{print $4}'`
if ("$mygid" != "") then
set first=`echo $mygid|awk '{print substr($0,0,1)}'`
if ("$first" == "4") then
# let me know who
echo $xx" "$mygid
endif
endif
endif
end