hi guys
I am trying to display a list of groups and the respective users:
Group1 : user1 user2 user3 ....
the closest thing I get is
echo " "; echo "Group Users "; echo " "; cat /etc/group |grep [5-9][0-9][0-9] | grep -v nfs
which I really don't since I want to remove the other stuff like x : and the group ID
something like I wrote before
Group1 : user1 user2 user3 ....
Group2 : user1 user4 user5 ....
thanks a lot
You could try this for the secondary groups
awk -F: '/[5-9][0-9][0-9]/{print $1" : "$4}' /etc/group
But note that you have to get primary group info from /etc/passwd.
you can try this
cat /etc/group | grep -v "^.*:$" | sed 's/\([a-zA-Z][a-zA-Z]*\):x:[0-9][0-9]*:\(.*\)/\1 : 2/'
methyl
April 12, 2010, 9:48am
4
A method which includes primary groups. Assumes you have the unix "logins" command. Script allows for more than one line in /etc/group for the same group (which can happen).
#!/bin/ksh
awk -F: '{print $1}' /etc/group| sort | uniq |while read GROUP
do
USERLIST=$( logins -g "${GROUP}" | awk '{print $1}' | sort |tr '\n' ' ' )
echo "${GROUP} : ${USERLIST}"
done
scrutinizer:
You could try this for the secondary groups
awk -F: '/[5-9][0-9][0-9]/{print $1" : "$4}' /etc/group
But note that you have to get primary group info from /etc/passwd.
thanks a lot I think this one does what I need
awk -F: '/[5-9][0-9][0-9]/{print $1" : "$4}' /etc/group | grep -v nfs