Skip to content

Instantly share code, notes, and snippets.

@qsun
Created January 3, 2011 00:50
Show Gist options
  • Save qsun/762980 to your computer and use it in GitHub Desktop.
Save qsun/762980 to your computer and use it in GitHub Desktop.
remove BOM (byte order mark) FEFF
#!/bin/sh
MD5=md5
function usage()
{
echo bom_removal.sh file
}
function remove_bom
{
filename=$1
echo backup $filename
mv $filename ${filename}.bak
dd if=${filename}.bak of=${filename} bs=3 skip=1
}
if [ ! -f "$0" ]; then
usage
exit 1
fi
filename=$1
echo check if $filename is BOM
bom=`dd if=$filename bs=3 count=1 2>/dev/null| MD5`
dd if=$filename bs=3 count=1 2>/dev/null| MD5
dd if=$filename bs=3 count=1 2>/dev/null| hexdump
if [ "$bom" = "ecaa88f7fa0bf610a5a26cf545dcd3aa" ]; then
remove_bom $filename
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment