How to convert ISO8859-15 to UTF8?

后端 未结 8 2024
情歌与酒
情歌与酒 2020-12-12 18:04

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          


        
8条回答
  •  Happy的楠姐
    2020-12-12 18:13

    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.

提交回复
热议问题