Using grep to search for hex strings in a file

后端 未结 6 2060
野趣味
野趣味 2020-12-04 17:46

I have been trying all day to get this to work. Does anyone know how to get grep, or something of the like, to retrieve offsets of hex strings in a file?

I have a bu

6条回答
  •  天命终不由人
    2020-12-04 18:43

    grep has a -P switch allowing to use perl regexp syntax the perl regex allows to look at bytes, using \x.. syntax.

    so you can look for a given hex string in a file with: grep -aP "\xdf"

    but the outpt won't be very useful; indeed better do a regexp on the hexdump output;

    The grep -P can be useful however to just find files matrching a given binary pattern. Or to do a binary query of a pattern that actually happens in text (see for example How to regexp CJK ideographs (in utf-8) )

提交回复
热议问题