问题
I need to compare two csv files in windows7. How can I proceed to achieve this. I want to see the differences in both the files , like we can use tkdiff in Linux.
回答1:
Suggestion:
- Press Windows+R shortcut to open windows' Run prompt
- Type in
cmdand press Enter to open aDOS terminalcmd window - Change the current path by running the command
cd C:\path\to\your\directoryto reach the location of the two CSV files
Tip: To paste a copied path from clipboard into DOS terminal cmd window, you can either (1) right-click on terminal window, or (2) press Shift+Insert.
- Finally, to compare the two files, run
fc filename1.csv filename2.csv > outfile.txt(fcstands for "file compare").
The command will also log the result of comparison into a text fileoutfile.txtlocated in the same folder. Ifoutfile.txtdoesn't exist, it will be created automatically.
回答2:
Here is another option which I found very useful, as mentioned here:
findstr /v /g:"file1.csv" "file2.csv"
Where the /v switch returns the differences and /g: gets the search strings from file1.csv. You can use findstr /? for more help.
You can also print the differences to a file using:
findstr /v /g:"file1.csv" "file2.csv > diffs.csv"
As an aside, I found findstr far more accurate and the output more readable than fc.
UPDATE
This works nicely with 'smaller' files. You might get an out of memory error on larger files. In this case, I've had to turn to Python and dataframes. Just a friendly heads up ...
回答3:
I did this today.
Lets say we have 2 csv files X and Y
X having columns a, b, c
Y having column a, b, c
The rows are not in same order and are disperesed througout the csv files.
I imported both of them in my excel sheet. I sorted them first by column c and then by column b and then by column a. You can go in any order you like.
Compare the sorted files through notepad++'s compare plugin/Beyond Compare.
来源:https://stackoverflow.com/questions/33523362/how-to-compare-two-csv-files-in-windows