Shell script to removes UTF-8 Byte Order Mark (BOM) from text files, where present.
1 2 3 4 5 6 7 8 9 | #!/bin/bash
for x in "$@"; do
if [[ "$(file "$x")" == *UTF-8\ Unicode\ \(with\ BOM\)* ]]; then
echo "Removing UTF-8 BOM for $x"
# The +4 tells it to tail from the 4th byte (skipping BOM)
tail -c +4 "$x" > "/tmp/killbom" || { echo "Failed to tail to /tmp/killbom"; exit 1; }
mv "/tmp/killbom" "$x"
fi
done
|