我有一个用ISO8859-15编码的阿拉伯语文件。如何将其转换为 UTF8?
我用过iconv
,但对我不起作用。
iconv -f ISO-8859-15 -t UTF-8 Myfile.txt
我想附上文件,但我不知道如何。
我有一个用ISO8859-15编码的阿拉伯语文件。如何将其转换为 UTF8?
我用过iconv
,但对我不起作用。
iconv -f ISO-8859-15 -t UTF-8 Myfile.txt
我想附上文件,但我不知道如何。
可能是您的文件不是 ISO-8859-15 编码的吗?您应该能够使用文件命令进行检查:
文件 YourFile.txt
此外,您可以使用 iconv 而不提供原始文件的编码:
iconv -t UTF-8 YourFile.txt
我发现这对我有用:
iconv -f ISO-8859-14 Agreement.txt -t UTF-8 -o agreement.txt
我们有这个问题并解决
创建一个名为 to-utf8.sh 的脚本文件
#!/bin/bash
TO="UTF-8"; FILE=$1
FROM=$(file -i $FILE | cut -d'=' -f2)
if [[ $FROM = "binary" ]]; then
echo "Skipping binary $FILE..."
exit 0
fi
iconv -f $FROM -t $TO -o $FILE.tmp $FILE; ERROR=$?
if [[ $ERROR -eq 0 ]]; then
echo "Converting $FILE..."
mv -f $FILE.tmp $FILE
else
echo "Error on $FILE"
fi
设置可执行位
chmod +x to-utf8.sh
进行转换
./to-utf8.sh MyFile.txt
如果要转换文件夹下的所有文件,请执行
find /your/folder/here | xargs -n 1 ./to-utf8.sh
希望有帮助。
就我而言,该file
命令告诉了一个错误的编码,所以我尝试使用所有可能的编码进行转换,并找到了正确的编码。
执行此脚本并检查结果文件。
for i in `iconv -l`
do
echo $i
iconv -f $i -t UTF-8 yourfile | grep "hint to tell converted success or not"
done &>/tmp/converted
您可以使用 ISO-8859-9 编码:
iconv -f ISO-8859-9 Agreement.txt -t UTF-8 -o agreement.txt
我遇到了同样的问题,但我在 这个页面找到了答案!它对我有用,你可以试试。
iconv -f cp936 -t utf-8
Iconv 只是将转换后的文本写入标准输出。您必须将其-o OUTPUTFILE.txt
用作参数或将标准输出写入文件。(iconv -f x -t z filename.txt > OUTPUTFILE.txt
或 iconv -f x -t z < filename.txt > OUTPUTFILE.txt
在某些 iconv 版本中)
Synopsis
iconv -f encoding -t encoding inputfile
Description
The iconv program converts the encoding of characters in inputfile from one coded character set to another.
**The result is written to standard output unless otherwise specified by the --output option.**
--from-code, -f encoding
Convert characters from encoding
--to-code, -t encoding
Convert characters to encoding
--list
List known coded character sets
--output, -o file
Specify output file (instead of stdout)
--verbose
Print progress information.