我想比较两个文本文件并将差异输出到另一个文本文件中。
$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
主机名_旧.txt
server02
server05
server04
server06
server01
主机名_新.txt
server04
server01
server02
Results
InputObject : server05
SideIndicator : <=
InputObject : server06
SideIndicator : <=
这就是我想要的:(摆脱InputObject和SideIndicator)
server05
server06
注意:一个输入文件具有重复条目的相关问题是这个问题 https://stackoverflow.com/q/54573751/45375.
只需使用-PassThru参数 https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.utility/compare-object:
compare-object (get-content c:\temp\hostname_old.txt) (get-content c:\temp\hostname_new.txt) -PassThru | Out-File $Location
正是你想要的。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)