The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



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

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Process id's in file names tekster757 UNIX for Dummies Questions & Answers 1 03-07-2008 12:29 PM
Dowloading a File from FTP Server to a local Server where User Id's are different ranjith_taurean Shell Programming and Scripting 1 02-22-2007 07:47 AM
Shell script to return all the ID's from file based on the distribution ID search kumbhatalok UNIX for Dummies Questions & Answers 1 10-06-2006 12:53 PM
User should not be allowed to change passwd brookingsd UNIX for Dummies Questions & Answers 3 01-23-2006 12:00 PM
Unix user ID's case-sensitive? dmilleville UNIX for Dummies Questions & Answers 3 12-14-2003 08:38 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 08-24-2007
LinuxRacr LinuxRacr is offline
Registered User
  
 

Join Date: Aug 2007
Location: DFW, Texas
Posts: 60
Looking for specific user ID's from the passwd file

Hello,

My issue is that I want to look for specific users that have their first and last initial followed by four numbers. For example:

ab1234

I've already got the user ID's out of the passwd file

Code:
more passwd | awk -F ":" '{print $1}' > userids
I just need to know how to just pick the users out of the list that are formated:

aannnn

a=alphabet
n=number

Thanks in advance!
  #2 (permalink)  
Old 08-24-2007
waiq waiq is offline
Registered User
  
 

Join Date: Aug 2007
Location: Sweden, Växjö
Posts: 3
from the top of my head. I think you can use somthing like this:
grep -e ^[:alpha:][:digit:]*
  #3 (permalink)  
Old 08-24-2007
LinuxRacr LinuxRacr is offline
Registered User
  
 

Join Date: Aug 2007
Location: DFW, Texas
Posts: 60
Thanks for the replay. Will that account for all the different userids that fit that pattern I mentioned above?

EDIT: I tried the following:

Code:
more passwd | awk -F ":" '{print $1}' | grep -e ^[:alpha:][:digit:]
and got a few users I didn't want like:

lp
adm

and some other users who didn't fit the EXACT pattern I asked for above.

I want to be able to list all users that fit the pattern below;

aannnn

example:

ab1234

Last edited by LinuxRacr; 08-24-2007 at 11:29 AM..
  #4 (permalink)  
Old 08-24-2007
Unbeliever Unbeliever is offline
Registered User
  
 

Join Date: Jul 2005
Location: England
Posts: 183
Code:
more passwd | awk -F ":" '{print $1}' | grep '[A-Za-z][A-Za-z][0-9][0-9][0-9][0-9]'
  #5 (permalink)  
Old 08-24-2007
LinuxRacr LinuxRacr is offline
Registered User
  
 

Join Date: Aug 2007
Location: DFW, Texas
Posts: 60
Unbeliever. That was the perfect answer! Thanks. I learn more everyday.
  #6 (permalink)  
Old 08-24-2007
Unbeliever Unbeliever is offline
Registered User
  
 

Join Date: Jul 2005
Location: England
Posts: 183
Code:
more passwd | awk -F ":" '{print $1}' | egrep '[A-Za-z]{2}[0-9]{4}'
Is slightly more compact but gives you exactly the same thing. Since the user id is the first field in the password file you could simply do:

Code:
egrep '^[A-Za-z]{2}[0-9]{4}:' /etc/passwd
  #7 (permalink)  
Old 08-24-2007
LinuxRacr LinuxRacr is offline
Registered User
  
 

Join Date: Aug 2007
Location: DFW, Texas
Posts: 60
Code:
egrep '^[A-Za-z]{2}[0-9]{4}:' /etc/passwd
Your egrep prints out not only the userids, but the other stuff after the first ":" also. Doesn't work.


Yet another method I found:

Code:
awk -F: '$1~"^[a-z]{2}[0-9]{4}$"{print $1}' /etc/passwd

Last edited by LinuxRacr; 08-24-2007 at 12:22 PM..
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 10:27 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0