如何grep文件中存在特定的十六进制字节? [英] How to grep for presence of specific hex bytes in files?
问题描述
我的Web应用程序正在显示一些异常输出(不应该存在的unicode字符,等等).我能想到的最好的办法是,我以某种方式在源代码中的某个地方引入了一个坏字符,但我不知道在哪里.
My web app is displaying some bizarro output (unicode characters that shouldn't be there, etc.). The best I can reckon is that somehow I introduced a bad char somewhere in the source, but I can't figure out where.
我找到了此答案,指出我可以执行以下操作:
I found this answer that states I can do something like:
grep -obUaP "<\x-hex pattern>" .
当我将Unicode字符从浏览器复制到我的 Bless 十六进制编辑器中时,它会告诉我char的确切字节是:
When I copy the unicode char out of the browser and into my Bless hex editor, it tells me that the exact bytes of the char are:
15 03 01 EF BF BD 02 02
15 03 01 EF BF BD 02 02
如何格式化<\xhex pattern>
以匹配我需要的确切字节.我试过了:
How can I format <\xhex pattern>
to match the exact bytes that I need. I tried:
grep -obUaP "<\x-15 03 01 EF BF BD 02 02>" .
但这不起作用.有想法吗?
But that doesn't work. Thoughts?
推荐答案
再次检查帖子. FrOsT不包含'<'和'>'在他实际的grep命令中.他只用克拉括了一个例子.他的实际陈述是这样的:
Check the post again. FrOsT is not including the '<' and '>' in his actual grep command. He only used the carats to enclose an example statement. His actual statement looks like this:
"\x01\x02"
不是:
"<\x01\x02>"
我的计算机上有一个以以下行开头的C源文件:
I have a C source file on my computer that begins with the line:
#include <stdio.h>
我跑步时
grep -obUaP '\x69\x6E\x63\x6C\x75\x64\x65' io.c
我知道
1:include
即,行号后跟 only 匹配模式的字符串.
That is, the line number followed by only the string matching the pattern.
您可能要运行
man grep
并找出所有这些选项的含义.
and find out what all those options mean.
这篇关于如何grep文件中存在特定的十六进制字节?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!