如果比较2个文本文件,如何获取txt文件中的文本行。 我有2个测试文件。 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")
但徒劳无功。
答案 0 :(得分:1)
compare-object
,那么 diff
是可悲的。根据我的最佳选择将是
fc
MS-DOS命令简单的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
*****