Remove Byte Order Mark (BOM) from files recursively

You are viewing revision #14 of this wiki article.
This version may not be up to date with the latest version.
You may want to view the differences to the latest version or see the changes made in this revision.

« previous (#13)next (#15) »

Ok, this wiki is not only for yii projects.

The problem was that all my web applications ran normally on localhost, but on server the Greek characters (or any other no-english characters) displayed with problems.

So, I needed to remove BOM from hundreds view files of Yii from a lot of Yii projects manually. Netbeans has an option to keep files Encoding in utf-8 but not utf-8 without BOM.

My previous solution was the converting in utf-8 without BOM encoding one by one file on notepad++ consuming a lot of my time!

Many servers has not this issue but for other servers this is important. So, after of two hours searching I found a fast way to do that by commands.

(If you have windows, install cygwin first)

1) Open a shell command, go into your root folder that contains the project

2) Run this command

grep -rl $'\xEF\xBB\xBF'  /home/rootfolder/Yii_project  > file_with_boms.txt

3) Now, Run this one

while read l; do sed -i '1 s/^\xef\xbb\xbf//'  $l; done < file_with_boms.txt

Thats it! The BOM will be removed from all files that contained it. Now you can upload your project on your server.

Note: Because I didn't use this way many times and I don't know if it works properly for all cases and files, make first a backup of your project! :)

2 1
7 followers
Viewed: 34 203 times
Version: Unknown (update)
Category: How-tos
Last updated by: samdark
Created on: Oct 2, 2013
Last updated: 5 years ago
Update Article

Revisions

View all history

Related Articles