Windows PowerShell:如何比较两个CSV文件并输出仅在文件中的两个行,而不是在两个文件中
我有一个文件 first.csv
name,surname,height,city,county,state,zipCode
John,Doe,120,jefferson,Riverside,NJ,8075
Jack,Yan,220,Phila,Riverside,PA,9119
Jill,Fan,120,jefferson,Riverside,NJ,8075
Steve,Tan,220,Phila,Riverside,PA,9119
Alpha,Fan,120,jefferson,Riverside,NJ,8075
和 second.csv
name,surname,height,city,county,state,zipCode
John,Doe,120,jefferson,Riverside,NJ,8075
Jack,Yan,220,Phila,Riverside,PA,9119
Jill,Fan,120,jefferson,Riverside,NJ,8075
Steve,Tan,220,Phila,Riverside,PA,9119
Bravo,Tan,220,Phila,Riverside,PA,9119
我想比较两个 first.csv 和 second.csv 文件并输出 first的行。
因此, output.csv 应该有
Alpha,Fan,120,jefferson,Riverside,NJ,8075
Bravo,Tan,220,Phila,Riverside,PA,9119
很多类似的问题,但是输出并不是我想要的。
谢谢
I have a file first.csv
name,surname,height,city,county,state,zipCode
John,Doe,120,jefferson,Riverside,NJ,8075
Jack,Yan,220,Phila,Riverside,PA,9119
Jill,Fan,120,jefferson,Riverside,NJ,8075
Steve,Tan,220,Phila,Riverside,PA,9119
Alpha,Fan,120,jefferson,Riverside,NJ,8075
and second.csv
name,surname,height,city,county,state,zipCode
John,Doe,120,jefferson,Riverside,NJ,8075
Jack,Yan,220,Phila,Riverside,PA,9119
Jill,Fan,120,jefferson,Riverside,NJ,8075
Steve,Tan,220,Phila,Riverside,PA,9119
Bravo,Tan,220,Phila,Riverside,PA,9119
I want to compare the rows of both first.csv and second.csv files and output the rows that are either in first.csv or second.csv but not in both.
So the output.csv should have
Alpha,Fan,120,jefferson,Riverside,NJ,8075
Bravo,Tan,220,Phila,Riverside,PA,9119
There are quite a few similar questions but the output is not exactly what I want.
Thank you
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我正在使用所有字段来在此处进行比较和排序,但是您可以指定要使用以匹配行的唯一值。
输出
I'm using the all the fields to compare and sort here but you can specify the unique value(s) that you're wanting to use to match the rows.
output
获取对称差异(从两个列表中的所有无关)实际上是一个很普遍的用途比较对象。
因此,我添加了此功能(#30 ) =“ https://www.powershellgallery.com/packages/join” rel =“ nofollow noreferrer”>
join-object script
/join-object module
(另请参阅:在PowerShell中,将两个桌子加入一张桌子的最佳方法是什么?)。为此,这个特定的问题:
Getting the symmetric difference (everything that is unrelated) from two lists is actually a quite common use in comparing objects.
Therefore, I have added this feature (#30) to the
Join-Object script
/Join-Object Module
(see also: In Powershell, what's the best way to join two tables into one?).For this for this specific question: