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


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting need a one liner to grep a group info from /etc/group and use that result to search passwd file
# 1  
Old 02-08-2012
need a one liner to grep a group info from /etc/group and use that result to search passwd file

/etc/group
Code:
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
Code:
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
# 2  
Old 02-08-2012
There could be more efficient ways. But I'm just extending your attempt to a working solution:
Code:
grep `grep 'tiadm' /etc/group  | awk -F: '{print $4}' | awk -F, '{print $1}'` /etc/passwd

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


Last edited by balajesuri; 02-08-2012 at 02:09 AM..
This User Gave Thanks to balajesuri For This Post:
# 3  
Old 02-08-2012
well that will just print password user information of one user.
# 4  
Old 02-08-2012
One awk:
Code:
awk -F: 'NR==FNR && $1==g{split($4,T,","); for(i in T) U[T[i]]; next} $1 in U' g=tiadm /etc/group /etc/passwd

This User Gave Thanks to Scrutinizer For This Post:
# 5  
Old 02-08-2012
Quote:
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
Wonder what you mean by "their info"?

If it's just the login name:
Code:
logins -g tiadm | awk '{print $1}'

If it's everything available and in a machine-readable format:
Code:
logins -xtog tiadm

This User Gave Thanks to methyl For This Post:
# 6  
Old 02-08-2012
Thanks scrutinizer code works..

Thanks metyl i didnt know a system command could do the work Smilie
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.
# 7  
Old 02-08-2012
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).
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Printing the user and group info

Hi All, i want to collect all the users info whose id greater than 999 and print the groups information which they belong. example : for user in $(cut -d: -f1,3 /etc/passwd | egrep ':{4}$' | cut -d: -f1); do groups $user; done centos : centos adm wheel systemd-journal balu : balu ... (2 Replies)
Discussion started by: balu1234
2 Replies

2. UNIX for Dummies Questions & Answers

Conflicting GID in group and passwd files.

Hi guys, I have a question. In the passwd file, user johndoe has a GID of 100 which is the group named users in the group file. But if you check the group file, johndoe is not listed under GID 100, but under GID 33, which is the group named videos. Under what group does johndoe really belong,... (1 Reply)
Discussion started by: goldenlight1814
1 Replies

3. UNIX for Dummies Questions & Answers

Inconsistency between passwd and group

Hi, I have a passwd file with 3 users belonging to the the root group (gid=0), but the group file does not list these users as members of the root group? Shoud I be worried and apart from manually changing it, how can it be remediated? thx Norgaard (1 Reply)
Discussion started by: Norgaard
1 Replies

4. Shell Programming and Scripting

search file and group values with problematic tab

hi people; the similar topic is being opened in here and here but i have confused with following condition. so i wanted to open a seperate topic. from my file.txt:... ... ... 110105-16:04:04 192.168.1.1 7.1j Port_NODE_MODEL_M_1_8 stopfile=/tmp/10544... (0 Replies)
Discussion started by: gc_sw
0 Replies

5. UNIX for Dummies Questions & Answers

Understanding group and passwd

Hi, I am checking who belong to the dba group , and found that oracle and autosys users are part of this group cat /etc/group | grep dba dba::400:oracle,autosys I thought to found user autosys under group 400 togther with user oracle , but found it in group 1000 as you can see bellow.... (2 Replies)
Discussion started by: yoavbe
2 Replies

6. Shell Programming and Scripting

Sort the file contents in each group....print the group title as well

I've this file and need to sort the data in each group File would look like this ... cat file1.txt Reason : ABC 12345-0023 32123-5400 32442-5333 Reason : DEF 42523-3453 23345-3311 Reason : HIJ 454553-0001 I would like to sort each group on the last 4 fileds and print them... (11 Replies)
Discussion started by: prash184u
11 Replies

7. Shell Programming and Scripting

Help on capturing /etc/group info.....!!

Gurus I am trying to capture all the data in /etc/group file in a CSV ,thru a fingerprinting engine. For hosts having ,unique group names and Ids ,following code works fine. Trouble starts when on a host,there are multiple groups defined with same name and id. e.g One of my hosts has 8... (10 Replies)
Discussion started by: ak835
10 Replies

8. Solaris

Secondary group info source

Experts, I know when I use id it shows only the primary group information for the given user, and that info comes from passwd file. When I use groups it shows all groups user are member of, however from where come information given by groups command? grep fmtt3990 /etc/passwd... (6 Replies)
Discussion started by: fmattos
6 Replies

9. UNIX for Dummies Questions & Answers

is it really not possible for me to edit the etc/group & the etc/passwd files?

From what I have read it possible to create a new group by editing the etc/group and etc/passwd in UNIX two files but a non-experienced user may face many problems such as destroying the file by mistake ot that his changes to these file does not make any difference. However, there is this... (2 Replies)
Discussion started by: whatev3r
2 Replies

10. UNIX for Dummies Questions & Answers

grep group and passwd file

How can I find find all members in the /etc/password file that belong to the dba group in the /etc/group file? (4 Replies)
Discussion started by: mozartny
4 Replies
Login or Register to Ask a Question