Skip to content

Instantly share code, notes, and snippets.

@jayli
Created April 20, 2012 03:48
Show Gist options
  • Select an option

  • Save jayli/2425762 to your computer and use it in GitHub Desktop.

Select an option

Save jayli/2425762 to your computer and use it in GitHub Desktop.
将文件一次性转换成unicode编码
#!/bin/sh
# sh ./unicode.sh
# 批量进行unicode转码,主要针对kissy和一些gbk编码的文件来一次性执行操作
# isEnc file.name gbk && echo 'gbk'
# isEnc file.name utf8 && echo 'utf8'
isEnc () {
local temp=`iconv -f $2 $1 1>/dev/null 2>/dev/null && echo 'true'`;
if [ "$temp" = 'true' ]; then
return 0;
fi;
return 1;
}
find . -name "*.css" > cssminfiles
find . -name "*.js" >> cssminfiles
while read line
do
isEnc ${line} gb18030 && iconv -f GB18030 -t UTF-8 ${line} -o ${line}.tmp
isEnc ${line} utf8 && cp ${line} ${line}.tmp
# isEnc ${line} utf8 && iconv -f UTF-8 -t GB18030 ${line} -o ${line}.tmp
native2ascii ${line}.tmp ${line}.tmp2
mv ${line}.tmp2 ${line}
rm ${line}.tmp
sed -i 's/^\\ufeff//' ${line}
echo '>>>'${line}
done < cssminfiles
rm cssminfiles
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment