dd388 / crals

Community Resource for Archivists and Librarians Scripting
24 stars 5 forks source link

add command to do byte comparisons #15

Closed nkrabben closed 7 years ago

nkrabben commented 7 years ago

Really handy when trying to compare two files byte-by-byte

kieranjol commented 7 years ago

LGTM - looks very useful.

nkrabben commented 7 years ago

Our specific use case was comparing two disc images of an audio CD. cmp -l path/to/disk1 path/to/disk2 | wc -l gave us the number of bytes that were different between the images. wc -c path/to/disk1 gave us the total bytes. Dividing the two gave us the error rate to see if it was in the error bound of a CD drive.

If this fuller use case fits into the site, I'd be happy to add it, but I'm not sure if it's too specific.

dd388 commented 7 years ago

I think the specific one would work, too! Knowing whether something was in the error bound of a CD drive sounds really helpful.

nkrabben commented 7 years ago

If I could figure out how to pipe each of these values into a math function...

Right now the process is 2 sepearate bash commands and then using a calculator.

dd388 commented 7 years ago

This is really nested, but I think it would work. Can you try it out on your test case?

echo "$(cmp -l path/to/disk1 path/to/disk2 | wc -l | tail -n 1)/$(wc -c path/to/disk1 | cut -d' ' -f4)" | bc -l

nkrabben commented 7 years ago

It works, but I'm not sure what the tail -n 1 is for. It worked without it.

I'm cooking up a pull request for the end of the day. Let me know if tail -n 1 is required or not

dd388 commented 7 years ago

Good catch; I was getting another line of output, but it's on stderr so you don't need tail -n 1.