&引用;Grep-ing“;在hexdump'中从A到B;s输出

&引用;Grep-ing“;在hexdump'中从A到B;s输出,grep,hexdump,Grep,Hexdump,情况如下:我必须在hextump的输出中找到字符串a和字符串B之间的字节。hextump的结构类似于: -random bytes -A + useful bytes + B -random bytes -A + useful bytes + B -random bytes 现在,问题是: -有可能把“从A到B”grep吗?我在手册页或互联网上都没有看到类似的内容。我知道我可以手动完成,但我需要编写脚本。 -是否可以在不显示行号的情况下显示hextump输出?这似乎很合理,但我还没有找到办法

情况如下:我必须在
hextump
的输出中找到字符串a和字符串B之间的字节。hextump的结构类似于:

-random bytes
-A + useful bytes + B
-random bytes
-A + useful bytes + B
-random bytes
现在,问题是: -有可能把“从A到B”grep吗?我在手册页或互联网上都没有看到类似的内容。我知道我可以手动完成,但我需要编写脚本。 -是否可以在不显示行号的情况下显示hextump输出?这似乎很合理,但我还没有找到办法

谢谢

grep
程序一次只能在一行上运行;你将无法让它在十六进制转储上智能地工作

我的建议是:使用perl或ruby或您最喜欢的脚本语言中的regex功能,为字符串grep原始二进制数据。ruby中的这个示例:

ARGF.read.force_encoding("BINARY").scan(/STR1(.*?)STR2/);
这将生成一个数组,其中包含STR1和STR2出现之间的所有二进制字符串。从那里,您可以通过
hextump(1)

运行每一个,您可以使用Perl-like来匹配A和B之间的所有内容,不包括A和B:

$ echo 'TEST test A foo bar B test' | grep -oP '(?<=A).*(?=B)'
 foo bar 
或者更好

hexdump filename | cut -d ' ' -f 2- | tr '\n' ' '
现在所有东西都在一条线上,所以
grep
必须是懒惰的,而不是贪婪的:

$ echo 'TEST test A foo bar B test A bar foo B test' | grep -oP '(?<=A).*?(?=B)'
 foo bar 
 bar foo 
$ echo 'TEST test A foo bar B test A bar foo B test' | grep -oP '(?<=A).*?(?=B)'
 foo bar 
 bar foo 
$ echo 'TEST test A foo bar B test A bar foo B test' | grep -oP 'A.*?B'
A foo bar B
A bar foo B