-2

This other question is excellent for joining two files. I need to do sort of the opposite. I need to remove lines from File A that are in File B, using powershell.

This question is similar to this other question, except that question is for unix and this is for Windows 7 powershell.

The files are hosts files. Each one has lines consisting of:

  • 127.0.0.1 host.domain.com

or

  • 0.0.0.0 host.domain.com

or

  • # this is a comment

Files may have up to 200,000 lines. Spaces and tabs may be present.

Although I prefer it to be preserved, order does not effect function.

Here are some examples of hosts files:

(Don't worry about 0.0.0.0 vs 127.0.0.1 for this question.)

1 Answers1

1

You can try this snippet:

$in1And2 = Compare-Object -ReferenceObject $file1 -DifferenceObject $file2 -PassThru -IncludeEqual -ExcludeDifferent
k7s5a
  • 1,287
  • 10
  • 18