The same file was loaded in to two different environments, and I need to compare the outputs (without opening them up)

My only thought is to compare the file size - because if they're both 5726kb then they must have the same contents. Apart from the file size, are there any other tests that will determine whether the files are identical without opening them up.

The files are .csv if that makes any difference in tools or techniques that can be used.

  • Please elaborate on what you mean by "without opening them up". Do you mean you are not allowed to use any tool that consumes the file content? Or do you mean you just can't eyeball the files?
    – user246
    Commented Jun 15, 2018 at 14:48
  • @user246 - the second one :)
    – dvniel
    Commented Jun 15, 2018 at 15:19

4 Answers 4


You can generate the hash of the contents, and then compare the hashes. If the hashes are identical, the files are the same.

In ruby it would look something like this.

md5hashFile1 = Hash(file1)
md5hashFile2 = Hash(file2)

expect(md5hashFile1).to eq(md5hashFile2)

That depends on what you mean when you say "open" and what result you anticipate when you compare. You have to read both files in some way to compare them. File size won't give you reliable result. Two files might have the same size but different content. Basically I can see two ways how you can compare files.

  1. byte-to-byte. you can either evaluate hash of each file and compare hashes, or read files byte-by-bite and compare the bites. This will answer the questions if the files are identical or not. You won't get more valuable information like what the difference is. You can extend this method by removing not-valuable part of information. Like removing empty lines or leading-or-trailing spaces (if such empty parts are really not informative).
  2. Parse the data structure from your files and compare the parts of structure. This is the most informative way, hence you can know what the difference is.

How about hashing the contents and comparing the results? As other folks say this requires opening the files in some fashion. So if you aren't allowed to see content you might need to create this as a service that protects the information and just exposes a SHA.

  • 1
    Be aware of the strength (in the security sense) of your hashing function before relying on hash codes to guarantee equality. See for example stackoverflow.com/questions/34446317/….
    – user246
    Commented Jun 15, 2018 at 20:04

You cannot make the assumption that if two files have the same size that they have the same content. Especially if they contain text data, like a csv file. One can open a file, change one or more letters, not add or delete, but change, and using your logic, they would be deemed identical.

If you absolutely MUST not open the file to compare, then at least check the date/time stamp in addition to size.. That can be altered, but in that case, at least there's a deliberate attempt to do so, and if you were concerned about tampering with data files, you would be reading and comparing the actual contents anyway.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.