2017-06-15 57 views
-1

This other question非常適合連接兩個文件。我需要做相反的事情。我需要使用powershell從文件B中的文件A中刪除行。如何使用Windows PowerShell刪除文件B中的文件A中的行

這個問題類似於this other question,除了問題是針對unix,這是針對Windows 7的powershell。

這些文件是主機文件。每一個具有由線:

  • 127.0.0.1 host.domain.com

  • 0.0.0.0 host.domain.com

  • # this is a comment

文件可能有多達200,000行。空格和製表符可能存在。

儘管我更喜歡它被保留下來,但是順序並不影響功能。

下面是主機文件的一些例子:

(不要擔心0.0.0.0 VS 127.0.0.1這個問題。)

回答

1

你可以試試這個片斷:

$in1And2 = Compare-Object -ReferenceObject $file1 -DifferenceObject $file2 -PassThru -IncludeEqual -ExcludeDifferent 
相關問題