I often use grep -ao ...word file.bin to look up a text content ("word") and the few characters before it; as a reminder:
-a, --text
Process a binary file as if it were text; this is equivalent to the --binary-files=text option.
-o, --only-matching
Print only the matched (non-empty) parts of a matching line, with each such part on a separate
output line.
Right; so just now, I realized that it behaves like this: I've tried first looking up the string war and one character before it:
$ grep -ao .war myfile.zip
/war
9war
$war
ʆwar
Ok, so I get 4 hits here. Now, if I want to look up looking up the string war and two more characters before it:
$ grep -ao ..war myfile.zip
>$war
So, now, for some reason, I get only one result?!
My guess is, the value of "two characters before" in the three missing cases is 0x00 (end of C string), so grep does not output that match - otherwise I would have still expected 4 results (unless the very first match previously was at start of file, otherwise I would have expected 3 results).
Can I somehow persuade grep to simply "ignore" null bytes in matches (or replace them with a dot or something) and still print matches that might have them? If not grep, is there another tool that could do this?
a\nbwaris not matched by..war, as well.war? For instance, in the example @MarcusMüller provided,a\nbwar, would you like to show\nbwarorabwar? What is the purpose of your question?