Welcome, guest | Sign In | My Account | Store | Cart

Shell script to removes UTF-8 Byte Order Mark (BOM) from text files, where present.

Bash, 9 lines
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
Created by Graham Poulter on Tue, 18 Oct 2011 (MIT)
Bash recipes (41)
Graham Poulter's recipes (7)

Required Modules

  • (none specified)

Other Information and Tasks