UCONV(1)
π UCONV(1) β the ICU 78.3 Manual, bestie edition π
okay so. welcome to uconv, straight out of the ICU 78.3 Manual. this is the little tool that takes your data and goes "bestie, this encoding? we're changing it." sit down, grab a strawberry π, and let's get into it.
β¨ NAME β¨
uconv β convert data from one encoding to another π¦
β¨ SYNOPSIS β¨
uconv [ -h, -?, --help ] [ -V, --version ] [ -s, --silent ] [ -v,
--verbose ] [ -l, --list | -l, --list-code code | --default-code | -L,
--list-transliterators ] [ --canon ] [ -x transliteration ] [
--to-callback callback | -c ] [ --from-callback callback | -i ] [
--callback callback ] [ --fallback | --no-fallback ] [ -b, --block-size
size ] [ -f, --from-code encoding ] [ -t, --to-code encoding ] [
--add-signature ] [ --remove-signature ] [ -o, --output file ] [ file...
]
β¨ DESCRIPTION β¨
so uconv converts, or transcodes, every file you hand it β or its standard input if you didn't hand it any file at all β from one encoding to another. and the way it does that? Unicode is the pivot. like, the data goes from its original encoding to Unicode first, and then from Unicode to the destination encoding. Unicode is literally the group chat everyone passes through. π
if an encoding isn't specified, or it's -, then the default encoding gets used. which means calling uconv with no encoding is a whole vibe for validating and sanitizing data files so other tools that need the default encoding can actually eat them. slay.
when you call uconv, you can specify callbacks that handle invalid characters in the input, or characters that just cannot be transcoded to the destination encoding. some encodings, for example, offer a default substitution character you can use to represent where those characters showed up in the input. other callbacks give you a genuinely useful visual representation of the invalid data. π
uconv can also run a specified transliteration on the transcoded data β in that case the transliteration happens as an intermediate step, after the data has been transcoded to Unicode. the transliteration can be either a list of semicolon-separated transliterator names, or an arbitrarily complex set of rules in the ICU transliteration rules format. either way, iconic.
for transcoding purposes, uconv's options are compatible with those of iconv(1), so dropping it into scripts in its place is easy peasy. BUT β and this is important β it is not necessarily the case that the encoding names used by uconv and ICU are the same as the ones iconv(1) uses. also, options that give you informational data, like the -l, --list one that some iconv(1) variants (GNU's, for example) offer, produce data in a slightly different and easier-to-parse format. so like, similar energy, not identical twins. π
β¨ OPTIONS β¨
-h,-?,--helpβ print help about usage and dip. π«Ά-V,--versionβ print the version ofuconvand dip.-s,--silentβ suppress messages while it's running. shhh. π€«-v,--verboseβ display extra informative messages while it's running. it's giving commentary.-l,--listβ list every available encoding, then exit.-l,--list-code codeβ list only thecodeencoding, then exit. ifcodeis not a proper encoding, it exits with an error. π--default-codeβ list only the name of the default encoding, then exit.-L,--list-transliteratorsβ list every available transliterator, then exit. β¨--canonβ if you use it with-l,--listor--default-code, the list of encodings comes out in a format compatible withconvrtrs.txt(5). if you use it with-L,--list-transliterators, it prints only one transliterator name per line. cute and tidy.-x transliterationβ run the giventransliterationon the transcoded Unicode data, and use the transliterated data as input for the transcoding to the destination encoding.--to-callback callbackβ usecallbackto handle characters that cannot be transcoded to the destination encoding. peek the CALLBACKS section below for the deets on which callbacks are valid. π-cβ omit invalid characters from the output. same as--to-callback skip.--from-callback callbackβ usecallbackto handle characters that cannot be transcoded from the original encoding. CALLBACKS section, again, for the valid list.-iβ ignore invalid sequences in the input. same as--from-callback skip.--callback callbackβ usecallbackto handle both characters that cannot be transcoded from the original encoding and characters that cannot be transcoded to the destination encoding. yes, both directions, one callback, main character energy. check CALLBACKS for what's valid.--fallbackβ use the fallback mapping when transcoding from Unicode to the destination encoding.--no-fallbackβ do not use the fallback mapping when transcoding from Unicode to the destination encoding. this is the default.-b,--block-size sizeβ read input in blocks ofsizebytes at a time. the default block size is4096.-f,--from-code encodingβ set the original encoding of the data toencoding.-t,--to-code encodingβ transcode the data toencoding.--add-signatureβ add aU+FEFFUnicode signature character (BOM) if the output charset supports it and doesn't add one anyway.--remove-signatureβ remove aU+FEFFUnicode signature character (BOM).-o,--output fileβ write the transcoded data tofile.
β¨ CALLBACKS β¨
uconv supports specifying callbacks to handle invalid data, and honestly? obsessed. callbacks can be set for both directions of transcoding: from the original encoding to Unicode, with the --from-callback option, and from Unicode to the destination encoding, with the --to-callback option.
here's the full list of valid callback names plus what each one actually does. the list of callbacks uconv actually supports gets displayed when you call it with -h, --help.
substituteβ write the encoding's substitute sequence, or the Unicode replacement characterU+FFFDwhen transcoding to Unicode.skipβ ignore the invalid data. bye. πstopβ stop with an error when encountering invalid data. this is the default callback. dramatic but fair.escapeβ same asescape-icu.escape-icuβ replace the missing characters with a string of the format%Uhhhhfor plane 0 characters, and%Uhhhh%Uhhhhfor planes 1 and above characters, wherehhhhis the hexadecimal value of one of the UTF-16 code units representing the character. characters from planes 1 and above are written as a pair of UTF-16 surrogate code units.escape-javaβ replace the missing characters with a string of the format\uhhhhfor plane 0 characters, and\uhhhh\uhhhhfor planes 1 and above characters, wherehhhhis the hexadecimal value of one of the UTF-16 code units representing the character. characters from planes 1 and above are written as a pair of UTF-16 surrogate code units.escape-cβ replace the missing characters with a string of the format\uhhhhfor plane 0 characters, and\Uhhhhhhhhfor planes 1 and above characters, wherehhhhandhhhhhhhhare the hexadecimal values of the Unicode codepoint.escape-xmlβ same asescape-xml-hex.escape-xml-hexβ replace the missing characters with a string of the format&#xhhhh;, wherehhhhis the hexadecimal value of the Unicode codepoint.escape-xml-decβ replace the missing characters with a string of the format&#nnnn;, wherennnnis the decimal value of the Unicode codepoint.escape-unicodeβ replace the missing characters with a string of the format{U+hhhh}, wherehhhhis the hexadecimal value of the Unicode codepoint. that hexadecimal string is of variable length and can use from 4 to 6 digits. this is the format universally used to denote a Unicode codepoint in the literature, delimited by curly braces so those substitutions are easy to spot in the output. π
β¨ EXAMPLES β¨
convert data from a given encoding to the platform encoding:
$ uconv -f encoding
check if a file contains valid data for a given encoding:
$ uconv -f encoding -c file >/dev/null
convert a UTF-8 file to a given encoding and make sure the resulting text is good for any version of HTML:
$ uconv -f utf-8 -t encoding \
--callback escape-xml-dec file
display the names of the Unicode code points in a UTF-file:
$ uconv -f utf-8 -x any-name file
print the name of a Unicode code point whose value is known (U+30AB in this example):
$ echo '\u30ab' | uconv -x 'hex-any; any-name'; echo
{KATAKANA LETTER KA}{LINE FEED}
$
(the names are delimited by curly braces. also, the name of the line terminator is also displayed. iykyk. π)
normalize UTF-8 data using Unicode NFKC, remove all control characters, and map Katakana to Hiragana:
$ uconv -f utf-8 -t utf-8 \
-x '::nfkc; [:Cc:] >; ::katakana-hiragana;'
β¨ CAVEATS AND BUGS β¨
bestie, listen. β οΈ
uconv reports errors as occurring at the first invalid byte encountered. this may be confusing if you're used to GNU iconv(1), which reports errors as occurring at the first byte of an invalid sequence. for multi-byte character sets or encodings, that means uconv error positions may be at a later offset in the input stream than would be the case with GNU iconv(1). not a vibe, just a fact. π
the reporting of error positions when a transliterator is used may be inaccurate or unavailable β in which case uconv will report the offset in the output stream at which the error occurred.
β¨ AUTHORS β¨
- Jonas Utterstroem
- Yves Arrouye
(legends, honestly π«Ά)
β¨ VERSION β¨
78.3
β¨ COPYRIGHT β¨
Copyright (C) 2000-2005 IBM, Inc. and others.
β¨ SEE ALSO β¨
and that's the whole page, bestie! π this one came to you from the ICU MANPAGE, dated 2005-jul-1 β yes she's been iconic since 2005 and she's still serving. go transcode something. π β¨π
π¦ where this page comes from
- arch rolling: icu 78.3-1 Β· LicenseRef-Unicode-3.0 AND BSD-2-Clause AND BSD-3-Clause AND NAIST-2003
- ubuntu stonking: icu-devtools 78.3-2ubuntu1 Β· MIT
- Copyright (C) 2016 and later: Unicode, Inc. and others
- Copyright (C) 2000-2013 IBM, Inc. and others
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms