User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the Shell Scripting section within the Software Development category of DaniWeb, a massive community of 391,568 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,644 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our Shell Scripting advertiser:
Views: 2878 | Replies: 8
Reply
Join Date: May 2005
Posts: 3
Reputation: moktod is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
moktod moktod is offline Offline
Newbie Poster

Removing entries

  #1  
May 19th, 2005
I have two files containing users, but the lists differ. My goal is to take all the users in file1 and remove them from file2. What would be a simple method for completing this?

-moktod
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Dec 2004
Location: Lincoln Park, Michigan
Posts: 1,744
Reputation: Comatose is an unknown quantity at this point 
Rep Power: 7
Solved Threads: 107
Colleague
Comatose's Avatar
Comatose Comatose is offline Offline
Moderator

Re: Removing entries

  #2  
May 19th, 2005
I have no idea how you would do that in Shell Scripting. I could do it in Perl fairly easily... but I think that might be a little bit of a task in Shell.
Reply With Quote  
Join Date: May 2005
Posts: 3
Reputation: moktod is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
moktod moktod is offline Offline
Newbie Poster

Re: Removing entries

  #3  
May 19th, 2005
I should be able to iterate through file1 and say if a match is found in file2, do some sed removal of that line, right? I suppose I would need the correct sed command.

-moktod
Reply With Quote  
Join Date: May 2005
Posts: 3
Reputation: moktod is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
moktod moktod is offline Offline
Newbie Poster

Re: Removing entries

  #4  
May 19th, 2005
Originally Posted by Comatose
I have no idea how you would do that in Shell Scripting. I could do it in Perl fairly easily... but I think that might be a little bit of a task in Shell.

How would you accomplish this in perl?

-moktod
Reply With Quote  
Join Date: Dec 2004
Location: Lincoln Park, Michigan
Posts: 1,744
Reputation: Comatose is an unknown quantity at this point 
Rep Power: 7
Solved Threads: 107
Colleague
Comatose's Avatar
Comatose Comatose is offline Offline
Moderator

Re: Removing entries

  #5  
May 19th, 2005
Sure, you could do that. It just seems like it would be more work in my opinion. Here is the link a sed man page: http://www.rt.com/man/sed.1.html, and a sed tutorial: http://www.selectorweb.com/sed_tutorial.html, and here is info on reading files in Bash: http://www.linuxgazette.com/node/8384.
Reply With Quote  
Join Date: Dec 2004
Location: Lincoln Park, Michigan
Posts: 1,744
Reputation: Comatose is an unknown quantity at this point 
Rep Power: 7
Solved Threads: 107
Colleague
Comatose's Avatar
Comatose Comatose is offline Offline
Moderator

Re: Removing entries

  #6  
May 19th, 2005
Well, This isn't the perl forum, so I probably shouldn't have posted that in here (my apologies). In Either language, though, I would read the first file, and compare it to each line of the second file. In perl, I'd read both into arrays, loop through and compare the arrays.
Reply With Quote  
Join Date: Dec 2004
Location: Lincoln Park, Michigan
Posts: 1,744
Reputation: Comatose is an unknown quantity at this point 
Rep Power: 7
Solved Threads: 107
Colleague
Comatose's Avatar
Comatose Comatose is offline Offline
Moderator

Re: Removing entries

  #7  
May 19th, 2005
Attached Is How I would do this with a Perl Script. I'm working on doing it in bash shell right now also... but it seems a bit more complicated to me.... maybe I just like the feel of perl better, and so it flows more naturally and easy to me... but I'll keep giving it a go in Shell.
Attached Files
File Type: zip cross-ref.zip (1.4 KB, 5 views)
Reply With Quote  
Join Date: Nov 2004
Posts: 21
Reputation: vgersh99 is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 0
vgersh99's Avatar
vgersh99 vgersh99 is offline Offline
Newbie Poster

Re: Removing entries

  #8  
May 20th, 2005
Originally Posted by moktod
I have two files containing users, but the lists differ. My goal is to take all the users in file1 and remove them from file2. What would be a simple method for completing this?

-moktod

look into 'man comm'
vlad
+-----------------------------------+
| #include <disclaimer.h> |
+-----------------------------------+
Reply With Quote  
Join Date: Dec 2004
Location: Lincoln Park, Michigan
Posts: 1,744
Reputation: Comatose is an unknown quantity at this point 
Rep Power: 7
Solved Threads: 107
Colleague
Comatose's Avatar
Comatose Comatose is offline Offline
Moderator

Re: Removing entries

  #9  
May 20th, 2005
Wow... Nice!
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

DaniWeb Shell Scripting Marketplace
Thread Tools Display Modes

Similar Threads
Other Threads in the Shell Scripting Forum

All times are GMT -4. The time now is 10:14 pm.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC