1

I have a large binary file e.g. a WAV file which I suspect might contain the whole sequence of bytes of a smaller WAV file.

How do I check if it does? If it does, how do I find the starting position?

Something like:

$ findguts big.wav small.wav
1234 # the contents of small.wav are found inside big.wav starting at byte #1234
3

With perl:

perl -l -0777 -ne '
  print "found at offset $o" if ($o = index($_, <STDIN>)) >= 0
  ' big.wav < small.wav

(note that both files are loaded in memory, so it doesn't scale to very large files).

1
  • 2
    Probably, we should consider the header of such files, e.g. for WAV I see that first 44 bytes is the header, which is file dependent (e.g. last part is the file size) so it seems meaningful to exclude it before search, with a tail or anything. (without having any idea about the wav format) – thanasisp Nov 24 '20 at 13:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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