- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - Linux
- >
- Looking for specific user ID's from the passwd fil...
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Discussions
Discussions
Forums
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-24-2007 03:23 AM
тАО08-24-2007 03:23 AM
My issue is that I want to look for specific userids that have their first and last characters are alphabetic followed by four numbers.
I've already got the user ID's out of the passwd file:
more passwd | awk -F ":" '{print $1}' > userids.txt
I just need to know how to just pick the users out of the list that are formated:
aannnn
a=alphabet
n=number
like for example:
ab1234
Thanks in advance!
Solved! Go to Solution.
- Tags:
- passwd
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-24-2007 03:30 AM
тАО08-24-2007 03:30 AM
Re: Looking for specific user ID's from the passwd file
awk has a print format function called printf
Take a look at that and you can do pattern matching.
You may also be able to use grep as a pre or post processor for this script.
SEP
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-24-2007 03:31 AM
тАО08-24-2007 03:31 AM
Re: Looking for specific user ID's from the passwd file
- Tags:
- grep
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-24-2007 03:31 AM
тАО08-24-2007 03:31 AM
Re: Looking for specific user ID's from the passwd file
# perl -aF":" -nle 'print $F[0] if $F[0]=~/[A-Za-z]+\d{4}$/' /etc/passwd
That is, split the field of the file on the ":" delimiter. If the first (zero-relative) field consists of one or more letters followed by exactly 4-digits, print the userid.
Regards!
...JRF...
- Tags:
- Perl
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-24-2007 03:31 AM
тАО08-24-2007 03:31 AM
Re: Looking for specific user ID's from the passwd file
grep [a-z][a-z][0-9][0-9][0-9][0-9] userids.txt
should work.
Pete
Pete
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-24-2007 03:34 AM
тАО08-24-2007 03:34 AM
Re: Looking for specific user ID's from the passwd file
Steven > awk has a print format function called printf. Take a look at that and you can do pattern matching
Hardly, 'printf' does formatted printing not pattern matching.
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-24-2007 03:41 AM
тАО08-24-2007 03:41 AM
Re: Looking for specific user ID's from the passwd file
I ended up doing this:
more passwd | awk -F ":" '{print $1}' | grep '[A-Za-z][A-Za-z][0-9][0-9][0-9][0-9]'
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-24-2007 03:45 AM
тАО08-24-2007 03:45 AM
Re: Looking for specific user ID's from the passwd file
# awk -F: '$1~"[a-z]{2}[0-9]{4}"{print $1}' /etc/passwd
~hope it helps
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-24-2007 03:49 AM
тАО08-24-2007 03:49 AM
Re: Looking for specific user ID's from the passwd file
> ended up doing this:
# more passwd | awk -F ":" '{print $1}' | grep '[A-Za-z][A-Za-z][0-9][0-9][0-9][0-9]'
That's a waste of two processes! Let 'awk' open and read the file instead of having 'cat' or 'more' spawn 'awk'. Then, let 'awk' do the matching that it was designed to do, eliminating the 'grep':
# awk -F":" '/[A-Za-z][A-Za-z][0-9][0-9][0-9][0-9]/ {print $1}' /etc/passwd
Regards!
...JRF...
- Tags:
- awk
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-24-2007 03:56 AM