- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Script user list
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
Forums
Discussions
Discussions
Discussions
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
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-27-2009 04:46 AM
08-27-2009 04:46 AM
This is in continuation to
http://forums13.itrc.hp.com/service/forums/questionanswer.do?threadId=1359353. Thanks to JRF and Dennis for helping me out. However it not capturing all the ID's. Here is what i exactly want. ID's like jk4567 (2 leters and 4 nos) and jk456e (2 letters, 3 nos and one letter). ONLY these 2 combinations need to be filtered and passed to the command, here is the current script..
logins -u | while read USERID X
do
echo ${USERID} | grep -q -E '^[a-zA-Z]+$' &&
done
Please help.
Best Regards
Mike.
Solved! Go to Solution.
- Tags:
- grep
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-27-2009 05:00 AM
08-27-2009 05:00 AM
Re: Script user list
For the 'grep' substitute:
grep -q -E '^[a-zA-Z]{2}[0-9]{3}[a-zA-Z0-9]$'
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-27-2009 05:24 AM
08-27-2009 05:24 AM
Re: Script user list
Please consider doing the filter before the read.
logins -u | grep -E "^[... " | while ..
It is not important here, assuming a low volume or rows (hundreds or thousands).
But for an application selecting thousands amongst millions of rows this order will avoid forking a grep process for every single row. That may be important for some usages, and just feels better for all.
Cheers,
Hein.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-27-2009 05:31 AM
08-27-2009 05:31 AM
Re: Script user list
Thanks, gave 7 points to keep this going (worth 100 :)). i found another grep, your comments please
grep ^[a-z][a-z][0-9][0-9][0-9][0-9,a-z]: /etc/passwd|cut -d: -f1
One more question JRF, now what if i want to EXCLUDE jk4567 and jk456e, meaning i want to run the some_command on all id's except the type jk4567 and jk456e? (only these type , exactly 6 characters in this combination only)
Thanks again
Best Regards
Mike
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-27-2009 05:44 AM
08-27-2009 05:44 AM
Re: Script user list
> i found another grep, your comments please
> grep ^[a-z][a-z][0-9][0-9][0-9][0-9,a-z]: /etc/passwd|cut -d: -f1
This looks for entries in '/etc/passwd' that begin (the ^) with two lowercase letters, followed by 3-digits, followed by either a digit or a lowercase letter and a ":". If that match is satistifed, then the first colon-delimited field is snipped (cut) from the stream. TMTOWTDI. I would have used 'awk' to match and print what I wanted in ONE process.
> One more question JRF, now what if i want to EXCLUDE jk4567 and jk456e, meaning i want to run the some_command on all id's except the type jk4567 and jk456e? (only these type , exactly 6 characters in this combination only)
One way to do this is to test for these exact matches and if seen, skip the loop:
logins -u | while read USERID X
do
[ "${USERID}" = "jk4567" ] && continue
[ "${USERID}" = "jk456e" ] && continue
echo ${USERID} | grep -q -E '^[a-zA-Z]{2}[0-9]{3}[a-zA-Z0-9]$' &&
done
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-27-2009 05:51 AM
08-27-2009 05:51 AM
Re: Script user list
Thanks (again), I think i presented my question wrongly, what i wanted was, i wanted run the cammonds on all ID's except of the format jk4567 (2 letters, 4 nos) and of the format jk456e (2 letters, 3 nos and one letter). I did not mean the exact ID jk4567 or jk456e, but instead all ID's of this format should be omitted and command should execute on other ID's.
Thanks
Mike
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-27-2009 05:55 AM
08-27-2009 05:55 AM
Re: Script user list
> Thanks (again), I think i presented my question wrongly, what i wanted was, i wanted run the cammonds on all ID's except of the format jk4567 (2 letters, 4 nos) and of the format jk456e (2 letters, 3 nos and one letter). I did not mean the exact ID jk4567 or jk456e, but instead all ID's of this format should be omitted and command should execute on other ID's.
OK, then using the techniques and regular expressions I have shown you, you should be able to do a 'continue' statement in the loop when a 'grep' returns a status (return code) indicating a match for that pattern.
You have the tools :-))
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-27-2009 10:29 AM
08-27-2009 10:29 AM
Re: Script user list
Thanks, you are truly great, i found the solution (but not w/o your help). Thanks again JRF
Best Regards
Mike
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-27-2009 10:21 PM
08-27-2009 10:21 PM
SolutionYou can use grep's -v, to exclude patterns.
>JRF: grep ^[a-z][a-z][0-9][0-9][0-9][0-9,a-z]:
>followed by either a digit or a lowercase letter and a ":".
I also see a comma inside []. It could just be a typo. Otherwise it also matches: aa000,:
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-28-2009 03:39 AM
08-28-2009 03:39 AM
Re: Script user list
> Dennis: I also see a comma inside []. It could just be a typo.
Yes, that is indeed a typo and should be eliminated. It was actually posted by Mike as a secondary question of how it worked. I missed that until you saw it :-)
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-29-2009 05:09 PM
08-29-2009 05:09 PM
Re: Script user list
Mike