Created
March 4, 2014 14:08
-
-
Save egulhan/9347093 to your computer and use it in GitHub Desktop.
How-to detect file with BOM and remove it
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Source: http://blog.x-if.com/2010/12/find-utf-8-files-with-bom/ | |
# http://stackoverflow.com/questions/204765/elegant-way-to-search-for-utf-8-files-with-bom | |
find -type f|while read file;do [ "`head -c3 -- "$file"`" == $'xefxbbxbf' ] && echo "found BOM in: $file";done | |
grep -orHbm1 "^`echo -ne 'xefxbbxbf'`" . | sed '/:0:/!d;s/:0:.*//' | |
# most efficient way: | |
find . -type f -print0 | xargs -0r awk '/^xEFxBBxBF/ {print FILENAME} {nextfile}' | |
# find and remove BOM: | |
find . -type f -exec sed -i 's/^xEFxBBxBF//' {} ; | |
# just remove BOM: | |
tail –bytes=+4 text.txt |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment