iconv any encoding to UTF-8

后端 未结 7 1550
天涯浪人
天涯浪人 2020-12-15 04:53

I am trying to point iconv to a directory and all files will be converted UTF-8 regardless of the current encoding

I am using this script but you have to specify wha

7条回答
  •  盖世英雄少女心
    2020-12-15 05:33

    Compiling all them. Go to dir, create dir2utf8.sh:

    #!/bin/bash
    # converting all files in a dir to utf8
    
    for f in *
    do
      if test -f $f then
        echo -e "\nConverting $f"
        CHARSET="$(file -bi "$f"|awk -F "=" '{print $2}')"
        if [ "$CHARSET" != utf-8 ]; then
          iconv -f "$CHARSET" -t utf8 "$f" -o "$f"
        fi
      else
        echo -e "\nSkipping $f - it's a regular file";
      fi
    done
    

提交回复
热议问题