比较两个文本文件并将差异写入文本文件 [英] Compare two text files and write the differences to text file

查看:255
本文介绍了比较两个文本文件并将差异写入文本文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想比较2个文本文件,然后将差异输出到另一个文本文件中.

I want to compare 2 text files and output the difference in another text file.

$Location = "c:\temp\z.txt"
compare-object (get-content c:\temp\hostname_old.txt) (get-content c:\temp\hostname_new.txt) | format-list | Out-File $Location

hostname_old.txt

hostname_old.txt

server02
server05
server04
server06
server01

hostname_new.txt

hostname_new.txt

server04
server01
server02

结果

InputObject   : server05
SideIndicator : <=

InputObject   : server06
SideIndicator : <=

这就是我想要的:(摆脱InputObject和SideIndicator)

This is what I want : (get rid of both InputObject and SideIndicator)

server05
server06

注意:一个输入文件具有重复条目的一个相关问题是此问题的主题.

Note: A related problem where one input file has duplicate entries is the subject of this question.

推荐答案

只需使用完全满足您的需求.

这篇关于比较两个文本文件并将差异写入文本文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆