Created
January 4, 2013 08:37
-
-
Save vivisidea/4450935 to your computer and use it in GitHub Desktop.
shell脚本转换文件编码
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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