[Ubuntu] Remove Byte Order Mark (BOM) from files recursively [Forward article]
Original article: http://www.yiiframework.com/wiki/570/remove-byte-order-mark-bom-from-files-recursively/
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! :)
shell script for replacing tab with spaces and remove bom head from file.
find /path/to/your/folder -type f -exec sed -i 's/\t/ /g' {} \; && grep -rl $'\xEF\xBB\xBF' /path/to/your/folder > file_with_boms.txt && while read l; do sed -i '1 s/^\xef\xbb\xbf//' $l; done < file_with_boms.txt && rm file_with_boms.txt
[Ubuntu] Remove Byte Order Mark (BOM) from files recursively [Forward article]的更多相关文章
- 字节顺序标记——BOM,Byte Order Mark
定义 BOM(Byte Order Mark),字节顺序标记,出现在文本文件头部,Unicode编码标准中用于标识文件是采用哪种格式的编码. 介绍 UTF-8 不需要 BOM,尽管 Unico ...
- LITTLE-ENDIAN(小字节序、低字节序) BOM——Byte Order Mark 字节序标记 数据在内存中的存放顺序
总结: 1. endian 字节存放次序 字节序,顾名思义字节的顺序,再多说两句就是大于一个字节类型的数据在内存中的存放顺序(一个字节的数据当然就无需谈顺序的问题了). 2. LITTLE-ENDIA ...
- UTF-8文件的Unicode签名BOM(Byte Order Mark)问题记录(EF BB BF)
背景 楼主测试的批量发送信息功能上线之后,后台发现存在少量的ERROR日志,日志内容为手机号码格式不正确. 此前测试过程中没有出现过此类问题,从运营人员拿到的发送列表的TXT,号码是符合规则的,且格式 ...
- StreamWriter结合UTF-8编码使用不当,会造成BOM(Byte Order Mark )问题生成乱码(转载)
问: I was using HttpWebRequest to try a rest api in ASP.NET Core MVC.Here is my HttpWebRequest client ...
- 文本编辑BOM标记(Byte Order Mark)
微软的自带记事本程序notepad.exe会给UTF-8编码的文件头加入三个隐藏的字节(即BOM).这是一种很愚蠢的做法.就是为了让编辑器不去猜测文件本身是ASCII码还是UTF-8. 什么是BOM ...
- 字节序(byte order)和位序(bit order)
字节序(byte order)和位序(bit order) 在网络编程中经常会提到网络字节序和主机序,也就是说当一个对象由多个字节组成的时候需要注意对象的多个字节在内存中的顺序. 以前我也基本只了 ...
- 编程-Byte order & Bit order
https://mp.weixin.qq.com/s/B9rKps4YsLiDTBkRks8rmQ 看到比特序和字节序放在一起被提及,想必就已经填补了概念拼图里面缺失的那一块了,这一块正是比特序. 一 ...
- ubuntu remove mysql
ubuntu 彻底删除 mysql 然后重装 mysql 删除 mysql sudo apt-get autoremove --purge mysql-server-5.0sudo apt-get r ...
- linux shell 命令学习(4) cut - remove sections from each line of files
之前写了split命令,split主要是按照行来进行文件的分割,而cut 是按照列来进行文件内容的选取 cut OPTION... [FILE]... 描述: 按列选取FILE的内容进行输出 -d : ...
随机推荐
- HTML5音频,视频播放
1.此方法可支持多种浏览器 <audio controls="controls"> <source src="1.mp3" ></ ...
- QcheckBox
#include "dialog.h" #include "ui_dialog.h" #include <QtCore> #include < ...
- SQL Server 2008 R2[ALTER]列属性修改
1:向表中添加字段 Alter table [表名] add [列名] 类型 2: 删除字段 Alter table [表名] drop column [列名] 3: 修改表中字段类型 (可以修 ...
- sell-- wordPOI
1. http://poi.apache.org/ 2.创建项目,结构如下 三: 查看效果 打开: 测试源码: /* ========================================= ...
- 编译mod_jk.so
编译mod_jk.so前,需要先到http://tomcat.apache.org/download-connectors.cgi去下载tomcat-connectors-1.2.41-src.tar ...
- Objective-C类成员变量深度剖析
目录 Non Fragile ivars 为什么Non Fragile ivars很关键 如何寻址类成员变量 真正的“如何寻址类成员变量” Non Fragile ivars布局调整 为什么Objec ...
- NavigationController popToViewController跳转之前任意ViewController方法
NSArray *viewControllers = self.navigationController.viewControllers;A *viewController = [viewContro ...
- 启用Service Broker
2015-10-20 17:31 整理,未发布数据库邮件配置向导,在选择配置任务页面点击下一步时,弹出"数据库邮件依赖于 Service Broker...".点击是,整个SSMS ...
- [GDAL]读取HDF格式的calipso数据
探测地球云层分布的CloudSat和CALIPSO卫星 http://www.nasa.gov/mission_pages/calipso/main/index.html http://www.nas ...
- Java jaxp查询节点
<?xml version="1.0" encoding="UTF-8"?> <person> <p1> <name& ...