Skip to content

Instantly share code, notes, and snippets.

@deadbok
Created January 5, 2016 19:59
Show Gist options
  • Save deadbok/a9374fcd83cfa289a54b to your computer and use it in GitHub Desktop.
Save deadbok/a9374fcd83cfa289a54b to your computer and use it in GitHub Desktop.
Add Byte Orders Mark to subtitles
#!/bin/bash
# addbom.sh
FILE=$1
check()
{
if (( e = "$1" )); then
echo "ERROR: $ACTION failed!!"
exit $e
else
echo "INFO: $ACTION Success!!"
fi
}
set_bom() {
ACTION="Setting utf-8 BOM"
# Detect if BOM already exists
BOM=`sed -n '1{/^\xEF\xBB\xBF/p}' $FILE`
if [ -z $BOM ]; then
[ -f "$FILE" ] && /usr/bin/vim -e -s +"set bomb|set encoding=utf-8|wq" $FILE
check $?
fi
}
set_bom
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment