Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
如何将带有 BOM 的 UTF8 转换为 UTF16LE?我已经使用了 iconv -f UTF8 -t UTF16 TEST.xml > TEST2.xml。使用十六进制编辑器检查内容时,它显示打印 UTF8 和 UTF16 (EF BB BF FF FE)。
我会为此写一个脚本。
#!/bin/sh # Usage: convert FILE ENCODING # Converts UTF-8 with BOM to target encoding bom=`printf '\xef\xbb\xbf'` if test "$bom" != `head -c 3 -- "$1"` ; then echo 1>&2 'error: no BOM found.' exit 1 fi tail -c +3 <"$1" | iconv -f UTF-8 -t "$2"