Click here to Skip to main content
15,885,546 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi All,

Please share if you have any idea to compare two csv files using vbscript or sql.

basically we are using qtp ,need to do comparison of two csv files.
so am looking to compare fastest way to compare and providing the report.

Adding more information,
i need to compare based on primary from file 1 to file2, if doesn't match then need to print that data in red color in the out put file(html format)along with entire record from two files and then continue to next record and do comparison again ....



Thanks,
Best friend
Posted
Updated 30-Oct-14 23:21pm
v2
Comments
Robert Welliever 31-Oct-14 5:04am    
It would be easy to just put a textreader on either file, then read it into a string. You can compare both lines of code for equality. That's barely any code, but then that only compares that the files have the exact same contents. What are you comparing? Just for equality?

The fastest way is to do the following on the command prompt :
c:\> fc.exe file1.csv file2.csv

But it really depends on what you want to do afterwards that counts, which you did not specify.
 
Share this answer
 
VB
Dim text1 As String = My.Computer.FileSystem.ReadAllText("C:\file1.csv")
Dim text2 As String = My.Computer.FileSystem.ReadAllText("C:\file2.csv") 
If text1 <> text2 Then 
  ' Do something because they're not equal
End If
 
Share this answer
 
I think you want your file to be compared line by line, You can do that in SQL but can not say that it will be fastest process. You would have to try all option and conclude which one best suites to you.

By bulk importing it in SQL DB tables which will have a ROWID column as identity been set, and then run a command to compare

SQL
select * from #file1 Join #file1 On #fil1e.ROwID=#file2.RowID
where #file1.Data<>#file2.Data 
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900