Skip to content

Instantly share code, notes, and snippets.

@kamikat
Created November 6, 2014 13:51
Show Gist options
  • Save kamikat/b98801acbae284e2cdd7 to your computer and use it in GitHub Desktop.
Save kamikat/b98801acbae284e2cdd7 to your computer and use it in GitHub Desktop.
Guessing text file encoding and outputs UTF-8 encoded text.
#!/bin/bash
for ENCODING in "gbk" "utf-8" "ucs-2"
do
(iconv -f $ENCODING -t utf-8 "$1" 1>/dev/null 2>&1) && iconv -f $ENCODING -t utf-8 "$1" && exit 0
done
echo >&2 "[ERROR] Unknown Characterset \"" "$1" "\""
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment