4

I have 2 huge text files and want to find the difference between them? What is the fast command/ utility/ or script to do this job?

I try using unix diff but, it failed for huge files. It show me "Permission Denied"

Also, I try unix bdiff (as I read that is good for huge files) but, I did not complete test it because it show me "bdiff: command not found"

Also, I try windows FC (file compare) but, I did not know how to show the output in a new text file. The result output in the cmd and I can't figure it all.

Any suggestion will help me a lot. Please help me in this matter.

Thanks a lot.

sara
  • 183
  • 1
  • 2
  • 13
  • 3
    `diff` is the way to go here, but you will have to make sure you have permission to access the files. Where are the files saved and what are the permissions on the files? – Munir Apr 12 '16 at 18:14
  • 4
    Please don't ask [the same question twice](http://stackoverflow.com/q/36516603/45375). – mklement0 Apr 12 '16 at 18:18
  • @Munir I put all test text files in the same folder and have full access to this folder. For small size files, it works but, for the huge one, it gives me that error. – sara Apr 12 '16 at 18:20
  • Are you sure the large files have the same permission as the small ones? – chepner Apr 12 '16 at 19:26
  • The number of lines are the same in both files? – Cyrus Apr 13 '16 at 04:51
  • @Cyrus no not the same. I try diff again, it does not show permission denied but, my computer hang for a long time then it shows: memory exahusted – sara Apr 13 '16 at 08:52
  • I suggest to take a look at [rdiff](http://stackoverflow.com/a/2033866/3776858). – Cyrus Apr 13 '16 at 17:37
  • @Cyrus what is rdiff? I read the post it sounds good but, is it cygwin utility? or what? from where can I download it? how to write it inside my php code? – sara Apr 15 '16 at 15:12
  • @Cyrus please help me. I want to test rdiff. I download something called: cwRsync_5.4.1_x86_Free Is it related to rdiff? – sara Apr 15 '16 at 17:01
  • [The rdiff utility uses the rsync algorithm to generate delta files with the difference from file A to file B (like the utility diff, but in a different delta format).](https://en.wikipedia.org/wiki/Rsync#rdiff) With Ubuntu you can install rdiff this way: `sudo apt-get install rdiff`. I don't know whether there is a port for cygwin or php. – Cyrus Apr 15 '16 at 17:14
  • @Cyrus I hope I am not bothering you. I am using Windows and I install cygwin cmd. I try to type: sudo apt-get install rdiff in cygwin but, I got: bash: sudo: command not found – sara Apr 15 '16 at 17:28
  • 1
    I suggest to ask at [Super User](http://superuser.com/tour). – Cyrus Apr 15 '16 at 17:34

2 Answers2

8

You can try diff with the --speed-large-files option :

diff --speed-large-files file1 file2

cmp is another alternative (compare files byte by byte) :

cmp file1 file2
SLePort
  • 15,211
  • 3
  • 34
  • 44
1

If fc works for you, you can send the output of fc to text file with:

fc file1 file2 >output.txt
Munir
  • 3,442
  • 3
  • 19
  • 29
  • Thanks. I try it now and I see the result in the new file but, it seems that it does not type the all mismatches! why? it works amazing for the huge file but, why not type all the mismatches? what I want exactly is like what diff do. – sara Apr 12 '16 at 18:30
  • Also, why there is: Resync Failed. Files are too different.? – sara Apr 12 '16 at 18:35
  • So it just try to find the (similarity) and stop comparing when there is a lot of mismatches! I do not want that. I want a tool that types all the differences exactly as diff utility. – sara Apr 12 '16 at 18:53