Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > how to do file1-file2?

Reply
Thread Tools

how to do file1-file2?

 
 
robertchen117@gmail.com
Guest
Posts: n/a
 
      03-13-2007
my files contains all lines of host names, also file2.

I want a shell could have the result : remove all the line in file1,
if the line is in the file2.

Please help. Thanks.

 
Reply With Quote
 
 
 
 
Ben Morrow
Guest
Posts: n/a
 
      03-13-2007

Quoth "(E-Mail Removed)" <(E-Mail Removed)>:
> my files contains all lines of host names, also file2.
>
> I want a shell could have the result : remove all the line in file1,
> if the line is in the file2.
>
> Please help. Thanks.


If you install the File::Slurp module, the following will do what you
want:

perl -MFile::Slurp -ne'
BEGIN{ @rej{read_file "file2"} = (); }
print unless exists $rej{$_};
' file1

To edit file1 in place use the -i switch (see perldoc perlrun).

Ben

--
Heracles: Vulture! Here's a titbit for you / A few dried molecules of the gall
From the liver of a friend of yours. / Excuse the arrow but I have no spoon.
(Ted Hughes, [ Heracles shoots Vulture with arrow. Vulture bursts into ]
'Alcestis') [ flame, and falls out of sight. ] http://www.velocityreviews.com/forums/(E-Mail Removed)
 
Reply With Quote
 
 
 
 
Tad McClellan
Guest
Posts: n/a
 
      03-13-2007
(E-Mail Removed) <(E-Mail Removed)> wrote:
> my files contains all lines of host names, also file2.
>
> I want a shell could have the result : remove all the line in file1,
> if the line is in the file2.



grep -v -f file2 file1 >newfile


--
Tad McClellan SGML consulting
(E-Mail Removed) Perl programming
Fort Worth, Texas
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM



Advertisments