how to do file1-file2?

R

robertchen117

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.
 
B

Ben Morrow

Quoth "[email protected] said:
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
 
T

Tad McClellan

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top