Maybe you don't have the right display tool to show Unicode text, or maybe you need to see details that a standard character display can't show you, or maybe you just want to see the 4-hex-digit code point value for some wide characters. This will show you the 4-hex-digit details.
# assuming 5.8.1 or later: perl -C9 -pe 's/([^[:ascii:]])/sprintf("\\x{%.4x}",ord $1)/eg' sometex +t.utf8 # that is, leave ascii data as-is, convert wide characters to "\x{HHHH +}"
If you leave off "-C9", you get to see the "underlying" utf8 byte sequences (in which case, a format of "\\x{%x}" would suffice), instead of the "official unicode reference" 4-hex-digit utf16 values. The "-C9" (same as "-CIi") causes STDIN and any input file handle to be read/interpreted as utf8 characters (i.e., works when reading from a pipe as well as from a file).

In fact, leaving off "-C9" makes it behave sort of like a typical hex-dump utility, except that only the bytes whose 8th bit is set will be converted to hex.

If your input is in some encoding other than utf8 and you want to see which unicode characters it will be turned into, do it like this (using Cyrillic as an example):

perl -pe 'BEGIN{binmode STDIN,":encoding(iso-8859-5)"} s/([^[:ascii:]] +)/sprintf("\\x{%.4x}",ord $1)/eg' < iso-cyrillic.txt

In reply to View Unicode in hex by graff

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.