gpt4 book ai didi

powershell - 在逐行比较情况下使用Compare-Object的逻辑是什么

转载 作者:行者123 更新时间:2023-12-02 23:14:24 24 4
gpt4 key购买 nike

我有以下csv文件:

csv file 1               csv file 2
------------ ------------
1,2,3,4,5 1,2,3,4,6
a,b,c,d,e 11,12,3,4,5
a,b,c,d,e 11,122,3,4,15
a,b,c,d,e 01,2,3,4,6
a,b,c,d,e
11,12,3,4,5
11,12,3,4,15
01,2,3,4,5

我使用以下命令进行比较:
compare-object (gc test1.csv) (gc test2.csv) -SyncWindow 1

输出为:
InputObject                                                 SideIndicator
----------- -------------
1,2,3,4,6 =>
1,2,3,4,5 <=
11,12,3,4,5 =>
a,b,c,d,e <=
11,122,3,4,15 =>
a,b,c,d,e <=
a,b,c,d,e <=
a,b,c,d,e <=
11,12,3,4,5 <=
11,12,3,4,15 <=
01,2,3,4,6 =>
01,2,3,4,5 <=

看起来对于前三行,该命令只是逐行进行比较,然后继续仅在文件1中存在的行,最后对 01,2,3,4,6行进行比较

我只是想知道为什么它在处理了前3行后就不继续第四行,是否有任何规则考虑文件2中的 01,2,3,4,6与文件1中的 01,2,3,4,5类似?如果是这样,为什么输出不是:
InputObject                                                 SideIndicator
----------- -------------
1,2,3,4,6 =>
1,2,3,4,5 <=
a,b,c,d,e <=
a,b,c,d,e <=
a,b,c,d,e <=
a,b,c,d,e <=
11,12,3,4,5 =>
11,12,3,4,5 <=
11,122,3,4,15 =>
11,12,3,4,15 <=
01,2,3,4,6 =>
01,2,3,4,5 <=

最佳答案

我看到您正在使用SyncWindow参数,这就是该命令表现为“奇怪”的原因。 Compare-Object文档描述了参数的功能,如下所示:

-SyncWindow<Int32>
Specifies the number of adjacent objects that Compare-Object inspects while looking for an match in a collection of objects. Compare-Object examines adjacent objects when it doesn't find the object in the same position in a collection. The default value is [Int32]::MaxValue, which means that Compare-Object examines the entire object collection.



如果省略该参数,该命令将按预期比较对象。

但是当查看带有参数的示例时,我看不到任何逻辑解释。

关于powershell - 在逐行比较情况下使用Compare-Object的逻辑是什么,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20369144/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com