53

我有一个用ISO8859-15编码的阿拉伯语文件。如何将其转换为 UTF8?
我用过iconv,但对我不起作用。

iconv -f ISO-8859-15 -t UTF-8 Myfile.txt

我想附上文件,但我不知道如何。

4

8 回答 8

53

可能是您的文件不是 ISO-8859-15 编码的吗?您应该能够使用文件命令进行检查:

文件 YourFile.txt

此外,您可以使用 iconv 而不提供原始文件的编码:

iconv -t UTF-8 YourFile.txt

于 2012-08-31T12:06:13.490 回答
34

我发现这对我有用:

iconv -f ISO-8859-14 Agreement.txt -t UTF-8 -o agreement.txt
于 2015-03-13T21:11:23.727 回答
13

我有 ubuntu 14 和其他不适合我的答案

iconv -f ISO-8859-1 -t UTF-8 in.tex > out.tex

我在这里找到了这个命令

于 2017-02-12T11:57:11.730 回答
6

我们有这个问题并解决

创建一个名为 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

希望有帮助。

于 2020-02-06T18:34:06.347 回答
3

就我而言,该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
于 2016-04-14T10:04:17.310 回答
2

您可以使用 ISO-8859-9 编码:

iconv -f ISO-8859-9 Agreement.txt -t UTF-8 -o agreement.txt
于 2016-08-17T15:52:48.067 回答
1

我遇到了同样的问题,但我在 这个页面找到了答案!它对我有用,你可以试试。

iconv -f cp936 -t utf-8 
于 2019-01-29T02:55:32.460 回答
0

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.
于 2017-06-21T13:28:14.450 回答