Skip to content

Instantly share code, notes, and snippets.

@sagan
Created October 21, 2013 02:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sagan/7077934 to your computer and use it in GitHub Desktop.
Save sagan/7077934 to your computer and use it in GitHub Desktop.
#!/bin/bash
if [[ $# < 1 ]]
then
printf "Usage: transcode_gbk <FILE>\n"
exit 1
fi
FILE="$1"
if [ ! -f "$FILE" ]
then
printf "Error: File '$FILE' Not Found\n"
exit 2
fi
if iconv -f GBK -t UTF-8 -o "$FILE.utf8" "$FILE"
then
mv "$FILE" "$FILE.delete"
mv "$FILE.utf8" "$FILE"
rm "$FILE.delete"
else
printf "Transcode failure\n"
rm "$FILE.utf8"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment