- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Scripting help
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
10-08-2004 03:50 AM
10-08-2004 03:50 AM
Simplest and/or most elegant and/or easiest to understand solution gets the full 10!!.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-08-2004 03:55 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-08-2004 03:57 AM
10-08-2004 03:57 AM
Re: Scripting help
>
Regards,
Jean-Luc
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-08-2004 03:59 AM
10-08-2004 03:59 AM
Re: Scripting help
# your_script_that_generates_the_list | perl -pe's/\b(203|merijn|skipme|baduser|488)\b//g' >zzz
Enjoy, Have FUN! H.Merijn [ who doen't know if -w is supported in all grep's on your machine ]
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-08-2004 03:59 AM
10-08-2004 03:59 AM
Re: Scripting help
grep -vE "^uid1$|^uid2$|^uid3$" file > newfile
The ^ and $ anchors ensure that for example removing "fred" doesn't also remove "frederick".
If you want to edit the file in-situ, you could do: -
ed file <
d
/^uid2$
d
/^uid23$
d
w
q
EOF
This will let you do it without a temporary "newfile".
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-08-2004 04:02 AM
10-08-2004 04:02 AM
Re: Scripting help
If they are the reserved users with UID < 100, you can simply use awk as follows:
awk '{if ($3 < 100) print}' /etc/passwd > newfile
If there are specific normal user's you're talking about, you can do similar to above specifying the UIDs of those users combined with the and operator:
awk '{if ($3 != 250 && $3 != 300) print}' /etc/passwd > newfile
or by username:
awk '{if ($1 != "joebob" && $1 != "nancysue") print}' /etc/passwd > newfile
Jeff Traigle
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-08-2004 04:03 AM
10-08-2004 04:03 AM
Re: Scripting help
Jeff Traigle
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-08-2004 04:04 AM
10-08-2004 04:04 AM
Re: Scripting help
Jeff Traigle
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-08-2004 04:07 AM
10-08-2004 04:07 AM
Re: Scripting help
cat /etc/passwd | awk -F: '{print $1, $2}' | uniq
The uniq function will get rid of repeats
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-08-2004 04:42 AM
10-08-2004 04:42 AM
Re: Scripting help
10 points to RAC for his insanely fast and simple answer. (Doh! grep! I know grep! Why didn't I think of that!)
10 points to Simon for his excellent addition to the simple answer that prevented a problem that I've had in the past where too much is removed. I'll be writing this solution down for other scripts I have as well.
10 points to Rick who unknowingly gave me a solution to a completely different scripting problem I was mulling.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-08-2004 04:45 AM
10-08-2004 04:45 AM
Re: Scripting help
awk '{ for ( i=1; i<=NF; i++) if ( $i != "user1" && $i != "user2" && $i != "user3" ) print $0 }'
IT will give the way to get user lists except your users.
HTH.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-08-2004 07:27 AM
10-08-2004 07:27 AM
Re: Scripting help
And in the perl statement, I did exactly the same: \b is word bound
Enjoy, Have FUN! H.Merijn
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-11-2004 12:33 AM
10-11-2004 12:33 AM
Re: Scripting help
So, if the list of user ids (one per line) is /tmp/uids:
grep -Fwv -f /tmp/uids file
should do what you want.
(As you're dealing with fixed strings, -F is probably faster than -E).
Andrew