Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
Search Forums:



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 03-10-2010
Registered User
 

Join Date: Mar 2010
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Number of users in passwd

This command prints out username/users in /etc/passwd:

Code:
cut -d ':' -f '1,5' /etc/passwd | sort

I wonder if I also, after above commands output, can get an output that lists number of users in the group? I need to use uniq to get rid of duplicates.
I´ve tried this, but cant get it right, can anyone help please?

Last edited by vbe; 03-10-2010 at 05:26 AM.. Reason: code tags
Sponsored Links
    #2  
Old 03-10-2010
Registered User
 

Join Date: Feb 2007
Posts: 113
Thanks: 4
Thanked 3 Times in 3 Posts
Try this :-

Code:
awk -F':' '{ print $3}' /etc/passwd   | sort  | uniq -c


Last edited by pludi; 03-10-2010 at 05:34 AM.. Reason: code tags, please...
Sponsored Links
    #3  
Old 03-10-2010
Registered User
 

Join Date: Mar 2010
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Ok, thank you, but I dont get the output, first 13 and then 1 and -2(?) up till 99.
Please help me to understand
Output:

[ 1 -2
1 0
1 1
1 26
1 27
1 4
1 54
1 55
1 56
1 58
1 59
1 60
1 65
1 67
1 70
1 71
1 72
1 73
1 74
1 75
1 76
1 77
1 78
1 79
1 82
1 83
1 84
1 85
1 86
1 87
1 88
1 89
1 91
1 92
1 93
1 94
1 95
1 96
1 97
1 99]
    #4  
Old 03-10-2010
Nila's Avatar
Registered User
 

Join Date: Feb 2010
Posts: 87
Thanks: 1
Thanked 0 Times in 0 Posts
I think Jairaj ,it should be $4 instead of $3.We can achieve it easily by cut command as follows.
This will give output as number of users in each group. First field is a no of users and second field is s group_id.


Code:
cut -d ':' -f 4 /etc/passwd | sort | uniq -c


Last edited by Nila; 03-10-2010 at 05:44 AM..
Sponsored Links
    #5  
Old 03-10-2010
Registered User
 

Join Date: Mar 2010
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
editing my last post

Dont know why but the post was missing 13 first in the output I wrote, adn dont mind the [] just for showing the oouput start and end.
Sponsored Links
    #6  
Old 03-10-2010
amitranjansahu's Avatar
Registered User
 

Join Date: Jan 2009
Location: Bangalore,INDIA
Posts: 503
Thanks: 4
Thanked 26 Times in 26 Posts
4Th field is the group id


Code:
awk -F':' '{ print $4}' /etc/passwd |sort -nr | uniq -c

Sponsored Links
Closed Thread

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
number of users logged in script vthokiefan Shell Programming and Scripting 1 08-29-2009 12:46 AM
Defaults number of users and Groups tirupathiraju_t Solaris 2 06-06-2009 09:09 AM
editing sqlplus id@passwd in multiple scripts, users and directories Helmi UNIX for Dummies Questions & Answers 8 05-09-2007 12:02 AM
append 3 users in /etc/passwd melanie_pfefer Shell Programming and Scripting 3 03-23-2007 05:36 AM
Maximum number of users allowed siza UNIX for Dummies Questions & Answers 10 06-18-2004 05:08 PM



All times are GMT -4. The time now is 12:54 AM.