如果比较两个文本文件,如何获取txt文件中的文本行。我有两个测试文件。mba.txt和mbanew.txt
mba.txt
Pre-Validation/SalesandServiceinvoicing,SalesandServiceinvoicing
Pre-Validation/SalesandServiceinvoicing/Salesinvoice,Salesinvoice
IDT-BTStarProject,IDT-BTStarProject,IDT
mbanew.txt
Pre-Validation/SalesandServiceinvoicing,SalesandServiceinvoicing
Pre-Validation/SalesandServiceinvoicing/Salesinvoice,Salesinvoice
IDT-BTStarProject,IDT-BTStarProject,IDT
IDT-BTStarProject/BBP,BBP
IDT-BTStarProject/ARIS,ARIS
IDT-BTStarProject/Servicetaxratemaster,Servicetaxratemaster
所以我想知道在mbanew.txt中遗漏了多少行文本文件,我需要得到这些文本行。在上面的例子中,我的答案是2,输出应该是:
IDT-BTStarProject/BBP,BBP
IDT-BTStarProject/ARIS,ARIS
IDT-BTStarProject/Servicetaxratemaster,Servicetaxratemaster
我尝试在PowerShell 中使用此代码
cls
compare-Object -referenceobject $(get-content "D:mba.txt") -differenceobject $(get-content "D:mbanew.txt")
但徒劳无功。
compare-object
如果您期望它的行为类似于unix diff
,那么它是可悲的。根据我的说法,最好的替代品将是
fc
MS-DOS命令- WinMerge GUI差异工具
一个简单的fc
使用将给出输出
`fc mba.txt mbanew.txt`
Comparing files mba.txt and mbanew.txt
***** mba.txt
Pre-Validation/SalesandServiceinvoicing,SalesandServiceinvoicing
Pre-Validation/SalesandServiceinvoicing/Salesinvoice,Salesinvoice
IDT-BTStarProject,IDT-BTStarProject,IDT
***** mbanew.txt
Pre-Validation/SalesandServiceinvoicing,SalesandServiceinvoicing
Pre-Validation/SalesandServiceinvoicing/Salesinvoice,Salesinvoice
IDT-BTStarProject,IDT-BTStarProject,IDT
IDT-BTStarProject/BBP,BBP
IDT-BTStarProject/ARIS,ARIS
IDT-BTStarProject/Servicetaxratemaster,Servicetaxratemaster
*****