Skip to content

Instantly share code, notes, and snippets.

@MJ111
Forked from akost/convert.sh
Last active August 9, 2017 06:10
Show Gist options
  • Save MJ111/eff7a316a1919b5f533542f44fc03b48 to your computer and use it in GitHub Desktop.
Save MJ111/eff7a316a1919b5f533542f44fc03b48 to your computer and use it in GitHub Desktop.
Bash script for recursive utf-8 byte order mark removal
#!/bin/bash
# Recursive utf-8 byte order mark removal
# https://en.wikipedia.org/wiki/Byte_order_mark#Byte_order_marks_by_encoding
# Place this file in the root of your site, add execute permission and run
# Converts *.php, *.html, *.css, *.js files.
# To add file type by extension, e.g. *.cgi, add '-o -name "*.cgi"' to the find command
find ./ -name "*.php" -o -name "*.html" -o -name "*.css" -o -name "*.js" -o -name "*.sass" -type f |
while read file
do
echo " $file"
mv $file $file.tmp
awk 'NR==1{sub(/^\xef\xbb\xbf/,"")}{print}' $file.tmp > $file
rm -rf $file.tmp
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment