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).# 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 +}"
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
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: View Unicode in hex
by gaal (Parson) on Sep 10, 2004 at 06:56 UTC | |
by Anonymous Monk on Dec 26, 2004 at 22:36 UTC |