When dealing with only local groups it’s easy to retrieve a group’s information, just look in /etc/group.
Retrieving group information from a directory, LDAP for example, requires more work.  You can quickly become entangled in commands specific to the directory your using.
There is an easier way, the getent command.

getent group | sort -t':' -k3 -n

This command will fetch all the groups, locally defined and from your directory server and list them.  In this example I’m sorting by GID.
While it should be obvious, the system you run the command on must be configured to use the directory server for its group information.
This technique should work for any of the databases getent(1) supports.