Looking for specific user ID's from the passwd file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Looking for specific user ID's from the passwd file
# 8  
Old 08-24-2007
Or (assuming GNU grep):

Code:
printf "%.6s\n" $(egrep -o '^[[:alpha:]]{2}[0-9]{4}:' /etc/passwd)

Or with GNU sed:

Code:
sed -nr 's/^([[:alpha:]]{2}[[:digit:]]{4}):.*/\1/p' /etc/passwd

Otherwise:

Code:
sed -n 's/^\([A-Za-z]\{2\}[0-9]\{4\}\):.*/\1/p' /etc/passwd

# 9  
Old 08-29-2007
Quote:
Originally Posted by LinuxRacr
Your egrep prints out not only the userids, but the other stuff after the first ":" also. Doesn't work.
Oops Smilie Smilie

Should of been:

Code:
egrep '^[A-Za-z]{2}[0-9]{4}:' /etc/passwd | awk -F':' '{print $1}'

or

egrep '^[A-Za-z]{2}[0-9]{4}:' /etc/passwd | sed -e 's/:.*//'

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

Granting access to specific user on a 700 file

Hello, I have a a directory dir1 with permissions 700 (yes wantedly) and is owned by user1:group1 rwx------ user1 group1 dir1I need to give permissions to user2 (belongs to group2) on dir1 and its files, so I granted the permissions using setfacl ; instead of adding the user to groups and... (3 Replies)
Discussion started by: karumudi7
3 Replies

2. UNIX for Advanced & Expert Users

Passwd file define user with special character

Hi all , The FTP user defind in my passwd file has ! in the hash password field and i want to know way is that its usually either MD5(Unix) hash or * can anyone explain to me i'm new for unix and want to learn this how my passwd file looks : ... (2 Replies)
Discussion started by: dahash11
2 Replies

3. Shell Programming and Scripting

want to search some content of the file with specific to user

I have some users in one unix system and i want to search some files with specific to user and then i want to find some content inside that file so can u help me how we can implement it? File location is as below. /pools/home_unix/cmadireddy/work/models/model/ cmadireddy is user name. now... (6 Replies)
Discussion started by: lathigara
6 Replies

4. UNIX for Dummies Questions & Answers

User info not present in passwd file

I have logged into a box with some userid,but in this box der is no entry for this userid in /etc/passwd file.this box is used by multiple users but none of them have their enteries in passwd file but for each user there is a directory in /home like for user1 /home/user1 for user2... (5 Replies)
Discussion started by: Jcpratap
5 Replies

5. Shell Programming and Scripting

Matching user alias's to their ID's in the passwd file

Hi, I've a user alias file in the below format.. I need to change all the ID's that come after the = sign (with some multiple ID's which are separated by comma's) to their respective users that are contained in the passwords file.. Whats the best way to go about this.. Some sort of sed command in... (2 Replies)
Discussion started by: Jazmania
2 Replies

6. UNIX for Advanced & Expert Users

allow user to use sudo cp on a specific directory and only a specific file

Is there a way to allow a user to use sudo cp on a specific directory and only a specific file? (6 Replies)
Discussion started by: cokedude
6 Replies

7. Programming

How to grep the specific string or user's list from the file

I have a file on UNIX system from where I want to grep the list of all users associated to the particular repository.If the user's list is in single line then I fetch all list but if it is in two separate lines it doesn't.I use the below command a=KESTREL-DEV;b=users;cat access_file|grep... (1 Reply)
Discussion started by: rohit22hamirpur
1 Replies

8. UNIX for Advanced & Expert Users

Determining if user is local-user in /etc/passwd or LDAP user

Besides doing some shell-script which loops through /etc/passwd, I was wondering if there was some command that would tell me, like an enhanced version of getent. The Operating system is Solaris 10 (recent-ish revision) using Sun DS for LDAP. (5 Replies)
Discussion started by: ckmehta
5 Replies

9. Shell Programming and Scripting

Locking specific account without using passwd

Hey guys just wondering how i could lock a specific acount by prepending LK to the password field in the /etc/shadow file. it cannot be done through a command since the script gets called by a menu driven interface so i cant use "passwd". Is there a way where i can search for a specific account... (11 Replies)
Discussion started by: musicmancanora
11 Replies

10. UNIX for Dummies Questions & Answers

How the /etc/passwd file is written when user does not have permission

Hi, /etc/passwd file has write permission only for the root user. Now when a normal user changes the its own password using passwd command, how this information has been written to the /etc/passwd file when the user is not having write permission to this file. ~santosh (2 Replies)
Discussion started by: santosh149
2 Replies
Login or Register to Ask a Question