- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: Script 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
07-08-2002 06:32 AM
07-08-2002 06:32 AM
I am trying to write a script that takes 2 lists of userID's and removes the contents of one from the other. For example, I am using the cut command to remove the first field from the /etc/passwd file. This leaves me with my first list of userID's. I also have a manually created list of users. This second list is much shorter.
I want a script that removes the users in the second (shorter) list from the longer passwd file generated list and outputs the remaining users to a file.
I'm sure some of you guys can help me out on this and I will be very greatful if you could do so.
Cheers,
Christian Briddon
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-08-2002 06:42 AM
07-08-2002 06:42 AM
Re: Script help
i don't have a system at hand right now. But i think something like this will work in the normal shell:
while read user
do
grep -v $user longfile > tmpfile
mv tmpfile longfile
done < shortfile
Where shortfile is your manually created list. Lonfile is your extract from /etc/passwd. And tmpfile is just a temp. file like /tmp/working.lst
But please do a test with some copied lists first. I don't want to be responsible for any loss of data ;-)
Hope this helps
Regards Stefan
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-08-2002 06:42 AM
07-08-2002 06:42 AM
Re: Script help
diff xx1 xx2 | grep '^<' | sed 's/< //' > newlist
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-08-2002 06:43 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-08-2002 06:47 AM
07-08-2002 06:47 AM
Re: Script help
let us suppose file A is the smaller file , and file B is the bigger file , to create file which should have all the users in file B but not in A then you can do like this
cat file A |
while read user
do
cat B | grep -v $user >> new file
done
this will do the job.
Manoj Srivastava
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-08-2002 06:55 AM
07-08-2002 06:55 AM
Re: Script help
i think Harry's method is the best and fastest. So 10 points to him.
Regards Stefan
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-08-2002 06:58 AM
07-08-2002 06:58 AM
Re: Script help
you don't have to use cat here. grep will read from the file directly. So using Harry's solution, this should be the fastest:
grep -v -f /tmp/short /tmp/long
Regards Stefan
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-08-2002 06:59 AM
07-08-2002 06:59 AM
Re: Script help
I like
grep -v -f short_file long_file > new_file
With the exception of having entries in the short_file look like "^userid$" instead of just "userid".
Then you will not remove "abc10", "abc1", or "test_abc" with a short_file entry of "abc".
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-08-2002 07:10 AM
07-08-2002 07:10 AM
Re: Script help
# cat /tmp/short
abc10
abc99
def5
# cat /tmp/long
abc01
abc02
abc03
abc10
abc55
abc77
abc99
bef01
def5
def6
def56
def65
# cat /tmp/long | grep -v -x -f /tmp/short
abc01
abc02
abc03
abc55
abc77
bef01
def6
def56
def65
#
or as put by Stefan:
grep -v -x -f /tmp/short /tmp/long
live free or die
harry
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-08-2002 08:17 AM
07-08-2002 08:17 AM
Re: Script help
comm -23 /path/to/longlist /path/to/shortlist
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-08-2002 10:47 AM
07-08-2002 10:47 AM
Re: Script help
As I can see your problem already is solved but if you are interested in shell programming
there is a command just for your need called "join". Have a look at it (man join).
In the example above it should look:
join -v 2 /tmp/short /tmp/long
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-08-2002 11:20 PM
07-08-2002 11:20 PM
Re: Script help
Christian Briddon