I'm up against a situation that seems like it must already have an implemented solution somewhere, but I'm having a tough time finding one. I'm looking for something that functions more or less exactly like strings (from binutils) but that only matches if the run of printable characters also ends with a null byte. As an additional hitch, I need the hex offset printed alongside each match (a la strings -tx).

I've seen a similar question that asks how to do it with grep. I guess something like that could work, if I can find a way to get grep to also output the hex offset like strings -tx does. But it seems to me that there should exist, somewhere, a tool that already does this natively.


Building on that similar question, grep can output decimal offsets. You can convert them to hex with awk.

grep -Eboz '[[:print:]]{4,}$' inputfile |
awk '{i=index($0,":");printf "%7x %s\n",$0+0,substr($0,i+1)}'

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.