
Python one-liner to compare two files (conditions apply) - vram22
http://jugad2.blogspot.com/2016/03/python-one-liner-to-compare-two-files.html
======
pklausler
Or do it in a language with lazy I/O and don't worry so much about memory
requirements.

import Data.ByteString.Lazy as LBS

areFilesEqual x y = (==) <$> LBS.readFile x <*> LBS.readFile y

(EDIT: added line break)

~~~
vram22
Haskell?

~~~
pklausler
Yes.

------
13of40
function cmp($l, $r) {"$(gc $l)" -eq "$(gc $r)"}

Though, in real life you should compare the lengths of the files before
reading them.

~~~
vram22
I do that in my program - compare lengths first. There's also an interesting
comment there by a reader about how filecmp (which can do the job) uses stat
info with a cache.

What language is that? shell? and what is gc?

~~~
13of40
PowerShell. GC is Get-Content. (It's actually horribly inefficient because it
tags every line read from the file with half a dozen metadata properties, but
it looks good in one-liners.)

------
ascotan
or you could just:

diff X Y

and check the return code.

Oh you crazy pythonistas.

~~~
vram22
You're either trolling, or just didn't / couldn't get that the post was for
fun and learning, exploring new/alternative ways of doing things.

> diff X Y

For that matter, doing:

cmp X Y

is even simpler since it doesn't create as much output as diff when the files
are different. And hey, we saved one letter over diff. /s

According to your logic, no one should have done an alternative version of a
program after the first one for that need was created. The world would be a
much poorer place. Only one language, assembly or FORTRAN /COBOL, only one OS,
one DB, etc.

Poor fellow - you crazy commenter.

