The described functionality can be achieved using standard utilities:
for u in $(getent group | grep '^g1:' | cut -d: -f4 | tr , '\n'); do
printf "%s(uid=%d)\n" $u $(id -u "$u")
done
Update: the command:
getent passwd | grep -E '^([^:]+:){3}'$(getent group | grep '^g1:' | cut -d: -f3)':' | cut -d: -f1
will retrieve lines from /etc/passwd corresponding to users whose primary group is g1. This can be combined with the previous command:
for u in $({ getent passwd | grep -E '^([^:]+:){3}'$(getent group | \
grep '^g1:' | cut -d: -f3)':' | cut -d: -f1; \
getent group | grep '^g1:' | cut -d: -f4 | tr , '\n'; }); do
printf "%s(uid=%d)\n" $u $(id -u "$u")
done | sort | uniq
with the added sorting and removal of duplicates at the end.
This command can be made into a shell function for convenience, using the group name as a parameter:
lid_replacement()
{
for u in $({ getent passwd | grep -E '^([^:]+:){3}'$(getent group | \
grep '^'$1':' | cut -d: -f3)':' | cut -d: -f1; \
getent group | grep '^'$1':' | cut -d: -f4 | tr , '\n'; }); do
printf "%s(uid=%d)\n" $u $(id -u "$u")
done | sort | uniq
}
# call as: `lid_replacement g1`
Edit: Updated regex to match the exact group name.
Edit 2: Updated to use getent(1) and added the function lid_replacement.