iconv
Text processing
Usage
iconv -f [from] -t [to] [file]Converts text from one character encoding to another; it stops at the first byte it cannot map unless you add -c, and it cannot guess the input encoding for you.
Common flags
| Flag | Meaning |
|---|---|
| -f | The encoding the input is in |
| -t | The encoding you want out |
| -l | List every encoding name this build knows |
| -c | Drop the characters that cannot be converted |
| //TRANSLIT | GNU: append to the target to swap unmappable letters for lookalikes |
Examples
iconv -f EUC-KR -t UTF-8 old.csv > new.csvFixes a legacy Korean CSV.
iconv -f UTF-8 -t ASCII//TRANSLIT text.txtTurns accented letters into plain ones (GNU).
iconv -l | grep -i 1252Checks that an encoding name is spelled right.
These were built to be piped together. Three joined commands are usually shorter than one that does everything.
How to read this
- Square brackets [ ] mark a part you may leave out.
- An ellipsis … means you can list more than one.
- Flags are case-sensitive — in some commands -r and -R do different things.
Questions
Q. What does iconv do?
Converts text from one character encoding to another; it stops at the first byte it cannot map unless you add -c, and it cannot guess the input encoding for you.
Q. How do I type it?
iconv -f [from] -t [to] [file] — square brackets mark the parts you can leave out.
Q. How many flags are worth knowing?
5 are listed here; the full set is in man iconv. This command sits under Text processing.
Related commands
man page: man iconv