I have a file (call it A, for reference) that may be a fragment of some other extant file on my system. I can't use cmp
because I don't know how many bytes may be missing from the start of A (or, at least, I can't use it without brute forcing through the -i flag). Is there a way for me to discover whether A is already existent on my system (using GNU tools, or any other linux program)? Or will I have to botch together a c++ program to do the job? Note: efficiency is desirable since the files that A has to be compared with may be numerous.
Asked
Active
Viewed 140 times
2

Zorawar
- 845
1 Answers
0
Not knowing how big the chunk (A) is ... have you considered grep'ing for its content using -a?

tink
- 6,765
echo -e "\x00\x11\x22\x33" > file; echo -e "\x00\x11" > snip; grep -a snip file
doesn't seem to work – daisy Oct 15 '12 at 23:59grep -a "$(cat snip)" file
. But, shouldn't there be a problem withecho
's newlines? Your example should fail regardless of this correction, shouldn't it? On my system it succeeds... – Zorawar Oct 16 '12 at 00:11grep -a
at all? Can't I just usegrep
? Taking warl0ck's example,echo -e "\x00\x11\x22\x33" > file; echo -e "\x00\x11Surplus Gibberish" > snip; grep -a "$(cat snip)" file
succeeds. Is that expected behaviour? If I remove the -a flag, then the command fails, as I'd want it to. – Zorawar Oct 16 '12 at 00:25