Reputation: 11720
I have an Arabic file encoded in ISO8859-15. How can I convert it into UTF8?
I used iconv
but it doesn't work for me.
iconv -f ISO-8859-15 -t UTF-8 Myfile.txt
I wanted to attach the file, but I don't know how.
Upvotes: 57
Views: 173160
Reputation: 999
I'm well aware that this question is over a decade old; nevertheless, I'd like to give another suggestion, namely, to use recode
— an old, but well-maintained utility tool, and which not only fully supports libiconv
, but it adds a few more character encodings, and, perhaps most interestingly, it allows in-place replacements of transcoded files — this means that the many solutions provided above that require making a copy first and then moving the final file to its destination (with the side-effect that the date of last modification of the original gets lost...) are not necessary.
I find recode
especially useful for changing ancient static HTML files from ISO-Latin-1 into UTF-8, while preserving the original date, and doing so recursively, if needed.
recode
is available from most package managers (Homebrew on macOS, apt on Debian/Ubuntu) but can also be retrieved from Reuben Thomas' GitHub repository, if needed, and locally compiled; it's being actively maintained and does regular releases.
Upvotes: 0
Reputation: 467
I have ubuntu 14 and the other answers where no working for me
iconv -f ISO-8859-1 -t UTF-8 in.tex -o out.tex
I found this command here
Upvotes: 15
Reputation: 899
We have this problem and to solve
Create a script file called 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
Set the executable bit
chmod +x to-utf8.sh
Do a conversion
./to-utf8.sh MyFile.txt
If you want to convert all files under a folder, do
find /your/folder/here | xargs -n 1 ./to-utf8.sh
Hope it's help.
Upvotes: 9
Reputation: 61
I got the same problem, but i find the answer in this page! it works for me, you can try it.
iconv -f cp936 -t utf-8
Upvotes: 6
Reputation: 31
in my case, the file
command tells a wrong encoding, so i tried converting with all the possible encodings, and found out the right one.
execute this script and check the result 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
Upvotes: 3
Reputation: 1
Iconv just writes the converted text to stdout. You have to use -o OUTPUTFILE.txt
as an parameter or write stdout to a file. (iconv -f x -t z filename.txt > OUTPUTFILE.txt
or iconv -f x -t z < filename.txt > OUTPUTFILE.txt
in some iconv versions)
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.
Upvotes: 0
Reputation: 820
You can use ISO-8859-9 encoding:
iconv -f ISO-8859-9 Agreement.txt -t UTF-8 -o agreement.txt
Upvotes: 2
Reputation: 1149
I found this to work for me:
iconv -f ISO-8859-14 Agreement.txt -t UTF-8 -o agreement.txt
Upvotes: 39
Reputation: 1064
Could it be that your file is not ISO-8859-15 encoded? You should be able to check with the file command:
file YourFile.txt
Also, you can use iconv without providing the encoding of the original file:
iconv -t UTF-8 YourFile.txt
Upvotes: 54