- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: script question
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-13-2007 05:01 AM
тАО08-13-2007 05:01 AM
i have 2 files called users and /etc/passwd.
I need to grep the users from /etc/passwd .
I'm using the below script ,...what is wrong.please advice
for i in $users ; do
>grep $i /etc/passwd >/tmp/users1
>done
Thanks much
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-13-2007 05:06 AM
тАО08-13-2007 05:06 AM
SolutionYou need a small modification in your script
for i in `cat users` ; do
grep $i /etc/passwd >> /tmp/users1
done
"cat users " I assume that the file is users and it has one field per record with the UID
">>" You need to put double redirect. otherwise you will only have the last successful record in the users1 file.
>> means add at the end where > means clear and add in this file.
good luck
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-13-2007 05:08 AM
тАО08-13-2007 05:08 AM
Re: script question
Thank you
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-13-2007 05:15 AM
тАО08-13-2007 05:15 AM
Re: script question
for i in $(
done
Rgds...Geoff
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-13-2007 05:33 AM
тАО08-13-2007 05:33 AM
Re: script question
# grep -f
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-13-2007 05:34 AM
тАО08-13-2007 05:34 AM
Re: script question
I like your oneline script.
very simple... =)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-13-2007 06:15 AM
тАО08-13-2007 06:15 AM
Re: script question
Say you have a file like:
tom
dick
harry
When you grep as the folks have done above you could get the users:
tom
tomsmit
dick
dickjr
harry
harry2
It would also be possible to gets matches in other areas of each line, like the home directory or GECOS field.
If you want to look for specific user names only you could do:
for i in $(
done
The '^${i}:' will look for ${i} ONLY at the beginning of each line with a ':' after it. So it would show only:
tom:*:UID:GID:GECOS:homedir:shell
dick:*:UID:GID:GECOS:homedir:shell
harry:*:UID:GID:GECOS:homedir:shell