|
Home > Archive > Unix Shell > October 2006 > Users of Same Group from /etc/passwd
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
Users of Same Group from /etc/passwd
|
|
| Rasheed 2006-10-26, 1:30 am |
| how can we show only those users who belong to same group using awk
programm.
i,e
GroupA user1 user5
Group B user2 user4
| |
|
| Rasheed wrote:
>
> how can we show only those users who belong to same group using awk
> programm.
> i,e
>
> GroupA user1 user5
> Group B user2 user4
Here's an example how to do it with user IDs and group IDs...
awk -F: '{u[$4] = u[$4] " " $3}
END {for (i in u) print i ": " u[i]}' /etc/passwd
If you want the literal names for groups and users (not their IDs)
you have to adjust the column numbers; for the groups you'd have
to read them from /etc/groups into a mapping table first...
awk -F: '
NR==FNR {g[$3]=$1}
NR!=FNR {u[$4]=u[$4]" "$1}
END {for (i in u) print g[i]": "u[i]}
' /etc/groups /etc/passwd
Janis
|
|
|
|
|