command-line - 从 XXX 到 utf-8 的字符集转换,命令行

标签 command-line encoding scripting character-encoding

我有一堆以 ISO-8851-2 编码的文本文件(有一些波兰语字符)。是否有用于 linux/mac 的命令行工具,我可以从 shell 脚本运行以将其转换为更清晰的 utf-8?

最佳答案

使用 iconv ,例如像这样:

iconv -f LATIN1 -t UTF-8 input.txt > output.txt

更多信息:
  • 您可能需要指定 UTF-8//TRANSLIT而不是普通 UTF-8 .引用联机帮助页:

    If the string //TRANSLIT is appended to to-encoding, characters being converted are transliterated when needed and possible. This means that when a character cannot be represented in the target character set, it can be approximated through one or several similar looking characters. Characters that are outside of the target character set and cannot be transliterated are replaced with a question mark (?) in the output.

  • 有关 iconv 接受的编码代码的完整列表,执行 iconv -l .
  • 上面的例子使用了 shell 重定向。确保您没有使用在重定向时破坏编码的 shell ——也就是说,不要为此使用 PowerShell。
  • 关于command-line - 从 XXX 到 utf-8 的字符集转换,命令行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2722477/

    相关文章:

    regex - 在两个标记字符串之间的字符串中查找/替换正则表达式模式

    forms - Spring 表单错误地解码撇号

    ajax - 如何防止 IE 缓存导致重复的 Ajax 请求?

    c# - 使用 MsBuild 命令行执行单元测试

    python - 如何处理未知编码

    linux - 在 Bash 中解析带有开始和结束定界符的字符串

    video - ffmpeg 无法扩展绘图文本

    java - 从命令行通过 stdin 访问 Java 应用程序

    linux - 如何复制文件及其路径下的所有目录

    algorithm - 编码/纠错挑战