Skip to content

Instantly share code, notes, and snippets.

@sagan
Created October 21, 2013 02:43
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/7077947 to your computer and use it in GitHub Desktop.
Save sagan/7077947 to your computer and use it in GitHub Desktop.
#!/bin/bash
if [[ $# < 1 ]]
then
printf "Usage: transcode_append_utf8_bom <FILE>\n"
exit 1
fi
UTF8_BOM=$(echo "0xef0xbb0xbf" | xxd -r)
FILEHEAD=$(head --bytes=3 $1)
if [ "$FILEHEAD" != "$UTF8_BOM" ]
then
# note will modify fileself
sed -i '1s/^/\xef\xbb\xbf/' $1
fi
#!/bin/bash
if [[ $# < 1 ]]
then
printf "Usage: transcode_jis <FILE>\n"
exit 1
fi
FILE="$1"
if [ ! -f "$FILE" ]
then
printf "Error: File '$FILE' Not Found\n"
exit 2
fi
iconv -f SHIFT-JIS -t UTF-8 -o "$FILE.utf8" "$FILE"
mv "$FILE" "$FILE.delete"
mv "$FILE.utf8" "$FILE"
rm "$FILE.delete"
#!/bin/bash
if [[ $# < 1 ]]
then
printf "Usage: transcode_remove_utf8_bom <FILE>\n"
exit 1
fi
# note will modify fileself
sed -i '1s/^\xef\xbb\xbf//' $1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment