1

How to get the lines of text in a txt file, if I compare 2 text files. I have 2 test 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  

So i want to find out how many lines of text file have been missed out in mbanew.txt and i need get those text lines. here in the above example, my answer is 2 and the output should be :

IDT-BTStarProject/BBP,BBP    
IDT-BTStarProject/ARIS,ARIS  
IDT-BTStarProject/Servicetaxratemaster,Servicetaxratemaster  

I tried with this code in PowerShell

cls
compare-Object -referenceobject $(get-content "D:\mba.txt") -differenceobject $(get-content "D:\mbanew.txt")

but in vain.

Etan Reisner
  • 77,877
  • 8
  • 106
  • 148
samolpp2
  • 139
  • 1
  • 13

1 Answers1

1

compare-object is pathetic if you expect it to behave something like a unix diff. Best alternatives according to me will be

  1. fc MS-DOS Command
  2. WinMerge GUI Diff Tool

A simple fc usage will give output as

`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
*****
Shreevardhan
  • 12,233
  • 3
  • 36
  • 50