#!/bin/bash
# debom
# =====
# Usage: debom TARGET [OUTPUT]
#
# Remove byte order mark (BOM) from a target file, saving to a new file
help_msg() {
cat <<-EOF
Remove BOM from a target file, saving to a new file
Usage: debom TARGET [OUTPUT]
Options:
-h, --help: print this message
EOF
exit 1
}
err_msg() {
(>&2 echo "$1")
exit 1
}
for i in "$@"; do
case $i in
-h|--help) help_msg;;
esac
done
if [ $# -lt 1 ]; then
err_msg "Usage: debom TARGET [OUTPUT]"
elif [[ $# -lt 2 ]]; then
OUTFILE="${1}.new"
else
OUTFILE="$2"
fi
sed '1s/^\xEF\xBB\xBF//' < "$1" > "$OUTFILE"