need a one liner to grep a group info from /etc/group and use that result to search passwd file

/etc/group

tiadm::345:mk789,po312,jo343,ju454,ko453,yx879,iy345,hn453
bin::2:root,daemon
sys::3:root,bin,adm
adm::4:root,daemon
uucp::5:root

/etc/passwd

mk789:x:234:1::/export/home/dummy:/bin/sh
po312:x:234:1::/export/home/dummy:/bin/sh
ju454:x:234:1::/export/home/dummy:/bin/sh
ko453:x:234:1::/export/home/dummy:/bin/sh
yx879:x:234:1::/export/home/dummy:/bin/sh
iy345:x:234:1::/export/home/dummy:/bin/sh
hn453:x:234:1::/export/home/dummy:/bin/sh
root:x:0:0:Super-User:/:/sbin/sh
daemon:x:1:1::/:
bin:x:2:2::/usr/bin:
sys:x:3:3::/:
adm:x:4:4:Admin:/var/adm:
lp:x:71:8:Line Printer Admin:/usr/spool/lp:
uucp:x:5:5:uucp Admin:/usr/lib/uucp:
nuucp:x:9:9:uucp Admin:/var/spool/uucppublic:/usr/lib/uucp/uucico

Now i need to search for tiadm group and then extract the users in that group and use it to find their info in password file

Please suggest some one liner. I am using solaris box

---------- Post updated at 12:58 AM ---------- Previous update was at 12:56 AM ----------

My try..

grep 'tiadm' /etc/group | awk -F: '{print $4}' | awk F, {print $1} --> after this i am blank

after this i am not sure how to use it.

i can do this with shell script but i am searching for one liner

There could be more efficient ways. But I'm just extending your attempt to a working solution:

grep `grep 'tiadm' /etc/group  | awk -F: '{print $4}' | awk -F, '{print $1}'` /etc/passwd

Here's another:

grep `grep 'tiadm' /etc/group  | sed 's/.*:\([^,]*\),.*/\1/'` /etc/passwd
1 Like

well that will just print password user information of one user.

One awk:

awk -F: 'NR==FNR && $1==g{split($4,T,","); for(i in T) U[T]; next} $1 in U' g=tiadm /etc/group /etc/passwd
1 Like

Wonder what you mean by "their info"?

If it's just the login name:

logins -g tiadm | awk '{print $1}'

If it's everything available and in a machine-readable format:

logins -xtog tiadm
1 Like

Thanks scrutinizer code works..

Thanks metyl i didnt know a system command could do the work :slight_smile:
one more query,i have seen in the password logins doesnt give correct information. i used to depend on passwd -s command to know the status.

The "logins" command does give the correct information about password status etc and you get more information than "passwd -s". Just beware of the date format (mmddyy).