Powershell 比较两个文件并生成第三个文件 [英] Powershell compare two files and generate third file
本文介绍了Powershell 比较两个文件并生成第三个文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有 2 个文件 - file1.txt 和 file2.txt.我想用powershell比较这两个文件并生成第三个文件(file3.txt),其中包含file1.txt中的所有行减去file2.txt中的行
I have 2 files - file1.txt and file2.txt. I want to compare these two files with powershell and generate third file (file3.txt) which containst all the lines from file1.txt minus lines in file2.txt
以下是文件 1 和 2 的示例:
Here is an example of how the files 1 and 2 looks like:
file1.txt 内容
file1.txt content
Line1
Line2
Line3
Line4
file2.txt 内容
file2.txt content
Line2
Line4
我希望 file3.txt 看起来像这样
And I want file3.txt to look like this
Line1
Line3
你能想出一些方法来做到这一点吗?
Can you think of some way how to do this?
推荐答案
这个方案简单得离谱...
This one is ridiculously easy...
Compare-Object (Get-Content File1.txt) -DifferenceObject (Get-Content File2.txt) -PassThru | Out-File File3.txt
仅此而已.
这篇关于Powershell 比较两个文件并生成第三个文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文