Overview
iconv converts the character encoding of text files or standard input to a specified different encoding. This is particularly useful when sharing files between different systems or working with applications that require specific encodings.
Key Features
- Supports various character encodings
- Processes files or standard input
- Provides options for handling conversion errors
- Saves results to a new file or outputs to standard output
Key Options
The iconv command requires options to specify the source and target encodings, and additionally, you can use options for error handling and specifying output files.
Conversion Settings
Information and Help
Generated command:
Try combining the commands.
Description:
`iconv` Executes the command.
Combine the above options to virtually execute commands with AI.
Usage Examples
Examples of performing various encoding conversion tasks using iconv.
Convert UTF-8 file to EUC-KR
iconv -f UTF-8 -t EUC-KR utf8_file.txt -o euc_kr_file.txt
Converts the utf8_file.txt file to EUC-KR encoding and saves it as euc_kr_file.txt.
Convert EUC-KR file to UTF-8 (ignore errors)
iconv -f EUC-KR -t UTF-8 -c euc_kr_file.txt
Converts euc_kr_file.txt to UTF-8, ignoring characters that cannot be converted. The result is output to standard output.
Check supported encoding list
iconv --list
Checks the complete list of all character encodings supported by iconv.
Convert via standard input
echo '안녕하세요 World' | iconv -f UTF-8 -t ASCII -c
Pipes the output of the echo command to iconv to convert from UTF-8 to ASCII. Characters that cannot be converted are ignored.
Tips & Precautions
Points to note and useful tips when using iconv.
Verify Encoding Names
You must use the correct encoding names. You can check the list of supported encodings with the `--list` option, or estimate the file's encoding using the `file -i <file>` command.
- Check Supported Encodings: iconv --list
- Estimate File Encoding: file -i <file>
Error Handling (-c Option)
If there are characters that cannot be converted to the target encoding, the conversion will be interrupted and an error message will be displayed if the `-c` option is not used. This option should be used with caution to prevent important data loss.
Backup Original Files
If you overwrite the original file using redirection without saving to a new file with the `-o` option, there is a risk of data loss. It is always recommended to back up important files before conversion.