Summary
iconv converts text between character encodings. When processing files from unknown sources, encoding mismatches are a constant problem — mojibake, invalid UTF-8, Latin-1 legacy files.
Requested Flags
| Flag |
Description |
-f encoding |
Source encoding (from) |
-t encoding |
Target encoding (to) |
-l |
List available encodings |
-c |
Silently discard characters that cannot be converted |
-o file |
Output to file instead of stdout |
//IGNORE |
Suffix on -t to skip unconvertible chars |
//TRANSLIT |
Suffix on -t to transliterate unconvertible chars |
Common Encodings to Support
| Encoding |
Description |
UTF-8 |
Default, most common |
ASCII |
7-bit ASCII |
ISO-8859-1 / LATIN1 |
Western European |
UTF-16 / UTF-16LE / UTF-16BE |
Windows Unicode |
CP1252 / WINDOWS-1252 |
Windows Western European |
ISO-8859-15 |
Latin-9 (Euro sign) |
Use Cases
# Convert Latin-1 file to UTF-8
iconv -f ISO-8859-1 -t UTF-8 legacy.txt > modern.txt
# Pipe conversion
curl -s https://example.com/data.csv | iconv -f CP1252 -t UTF-8 | csvtool ...
# Strip non-ASCII characters
iconv -f UTF-8 -t ASCII//TRANSLIT input.txt
# List available encodings
iconv -l
Implementation Notes
- Rust's
encoding_rs crate handles most common encodings
- Operates on VFS file contents (byte-level)
- Default target encoding should be UTF-8
//IGNORE and //TRANSLIT suffixes on target encoding are important usability features
Summary
iconvconverts text between character encodings. When processing files from unknown sources, encoding mismatches are a constant problem — mojibake, invalid UTF-8, Latin-1 legacy files.Requested Flags
-f encoding-t encoding-l-c-o file//IGNORE-tto skip unconvertible chars//TRANSLIT-tto transliterate unconvertible charsCommon Encodings to Support
UTF-8ASCIIISO-8859-1/LATIN1UTF-16/UTF-16LE/UTF-16BECP1252/WINDOWS-1252ISO-8859-15Use Cases
Implementation Notes
encoding_rscrate handles most common encodings//IGNOREand//TRANSLITsuffixes on target encoding are important usability features