1832947 Members
3035 Online
110048 Solutions
New Discussion

Re: passwd file

 
SOLVED
Go to solution
Anthony khan
Frequent Advisor

passwd file

Hi Guys, I need to get the username, userid, groupid and comments from /etc/passwd and then sort it, can anyone help me out.

Thanks
9 REPLIES 9
Hai Nguyen_1
Honored Contributor
Solution

Re: passwd file

Assume that you want to sort by users' names.

# awk -F: '{print $1 " " $3 " " $4 " " $5}' | sort

Hai
Trond Haugen
Honored Contributor

Re: passwd file

# cat /etc/passwd | cut -f1,3-5 -d: | sort

Regards,
Trond
Regards,
Trond Haugen
LinkedIn
Darrell Allen
Honored Contributor

Re: passwd file

Hi,

awk -F: '{printf "%-10s %6s %6s %-25s\n", $1, $3, $4, $5}' /etc/passwd | sort

Darrell
"What, Me Worry?" - Alfred E. Neuman (Mad Magazine)
S.K. Chan
Honored Contributor

Re: passwd file

The script would look like this ..(call it testscript)

#!/bin/ksh
IFS=:
exec 0while read -r Name PW UID GID Gecos Home Shell
do
print "$Name $UID $GID $Gecos"
done

This is how you can run it ..

# testscript | sort

Sukant Naik
Trusted Contributor

Re: passwd file

Hi Khan,

You can use the cut command on /etc/passwd file and extract the information.

1. to get the username
cut -d":" -f1 /etc/passwd

2. To get the userid
cut -d":" -f3 /etc/passwd

3. To get the groupid
cut -d":" -f4 /etc/passwd

and the comments
cut -d":" -f5 /etc/passwd

Regards,

Sukant
Who dares he wins
Hai Nguyen_1
Honored Contributor

Re: passwd file

I was missing the input file /etc/passwd in my command which should be:

# awk -F: '{print $1 " " $3 " " $4 " " $5}' /etc/passwd | sort

Hai


Justo Exposito
Esteemed Contributor

Re: passwd file

Hi,

This is only an optimized version for the cut solution:
cut -d":" -f1,3,4,5 /etc/passwd |sort

Regards,

Justo.
Help is a Beatiful word
Niraj Kumar Verma
Trusted Contributor

Re: passwd file

Hi,

Here is a good one !! use the
following hp-ux command

# /usr/sbin/logins -t


--Niraj
Niraj.Verma@philips.com
Yogeeraj_1
Honored Contributor

Re: passwd file

hi,

i would also add the "-m" option to the logins command to display multiple group membership data.

logins -t -m

hope this helps

Best Regards
yogeeraj
No person was ever honoured for what he received. Honour has been the reward for what he gave (clavin coolidge)