How to grep for presence of specific hex bytes in files?


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 <a href="https://stackoverflow.com/a/17168847" rel="nofollow">this answer</a> that states I can do something like:

grep -obUaP "<\x-hex pattern>" .

When I copy the unicode char out of the browser and into my <a href="http://home.gna.org/bless/" rel="nofollow">Bless</a> hex editor, it tells me that the exact bytes of the char are:


15 03 01 EF BF BD 02 02


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?


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:




I have a C source file on my computer that begins with the line:

#include <stdio.h>

When I run

grep -obUaP '\x69\x6E\x63\x6C\x75\x64\x65' io.c

I get


That is, the line number followed by <em>only</em> the string matching the pattern.

You may want to run

man grep

and find out what all those options mean.


  • Passing code reference to external module
  • Getting “… used only once: possible typo” warning when aliasing subroutines
  • CGI Commandline Args Disappearing
  • Service Fabric - how to gracefully fail an app
  • inserting hex value into mysql
  • How do I write to registers in hardware using Python?
  • Matplotlib: Custom colormap with three colors [duplicate]
  • How do I embed a custom user-control in MS Word?
  • Should I optimize around reads or CPU time in Google App Engine
  • gulp.watch running same task multiple times when saving many files
  • Equivalent of branch..merge for git-push
  • Android application not restoring state when installed from .apk, works fine from eclipse
  • CKeditor stripping font tags instead of converting to span
  • PHP UTF-8 to GB2312
  • How can I add div content to a new page in jspdf?
  • remove unicode characters but keep all special and English characters with preg_replace
  • Most efficient way to move table rows from one table to another
  • Python cosine function precision [duplicate]
  • HttpClient: disabling chunked encoding
  • what makes a request a new request in asp.net C#
  • Trying to get the char code of ENTER key
  • Why use database factory in asp.net mvc?
  • std::remove_copy_if_ valgrind bytes in block are possibly lost in loss record
  • System.InvalidCastException: Specified cast is not valid
  • preg_replace Double Spaces to tab (\\t) at the beginning of a line
  • Functions in global context
  • Read a local file using javascript
  • Extracting HTML between tags
  • MongoDB in PHP using aggregate to group by _id is null not working
  • Why HTML5 Canvas with a larger size stretch a drawn line?
  • Apache 2.4 and php-fpm does not trigger apache http basic auth for php pages
  • WinForms: two way TextBox problem
  • Why winpcap requires both .lib and .dll to run?
  • XCode can't find symbols for a specific iOS library/framework project
  • R: gsub and capture
  • What are the advantages and disadvantages of reading an entire file into a single String as opposed
  • Observable and ngFor in Angular 2
  • How to Embed XSL into XML
  • UserPrincipal.Current returns apppool on IIS
  • Conditional In-Line CSS for IE and Others?