Skip to content

Instantly share code, notes, and snippets.

@vivisidea
Created January 4, 2013 08:37
Show Gist options
  • Save vivisidea/4450935 to your computer and use it in GitHub Desktop.
Save vivisidea/4450935 to your computer and use it in GitHub Desktop.
shell脚本转换文件编码
#!/bin/bash
# description : shell script to convert a project file from one encoding to another encoding
# usage : ./convert to generate output and confirm, then run ./convert --notest to take effect
# create by : scutweiqiang.yang[AT]gmail.com
# date : 2013-01-04
files=$(find . -type f -regextype posix-extended -regex ".*\.java$|.*\.txt$")
from=gbk
to=utf8
for file in $files; do
# enca -L zh_CN $file | grep $from
# if [ $? -eq 0 ]; then
echo "converting $file from $from to $to ..."
iconv -f $from -t $to $file -o ${file}.$to
[ $# -eq 1 ] && [ $1 = "--notest" ] && mv ${file}.$to $file
# fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment