[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 : ...
随机推荐
- 浅谈ASP.Net ProcessPostData方法
其实这两次方法做的都是同一件事儿,让我们来看下图片中的代码,唯一的区别就是两次传入的参数不一样,一个是postData集合和Page_Load加载前的标记,另一个是leftoverPostData集合 ...
- dom classList
才发现dom对象就有classList属性,通过它可以判断该dom是否有指定的class名存在. var tar = e.target; var classList = tar.classList; ...
- LightOj1190 - Sleepwalking(判断点与多边形的位置关系--射线法模板)
题目链接:http://lightoj.com/volume_showproblem.php?problem=1190 题意:给你一个多边形含有n个点:然后又m个查询,每次判断点(x, y)是否在多边 ...
- Selenium2学习-019-WebUI自动化实战实例-017-获取浏览器类型
Web UI 自动化脚本分布执行过程中有时候需要获取浏览器的相关信息,此文给出了一个简略获取浏览器类型的方法,敬请各位小主们参阅.若有不足之处,敬请大神指正,不胜感激! 闲话少述,上码. /** * ...
- php图片处理函数自定义画图和引入图片
<?php //创建画布,就是画画的位置 imagecreate() //为图像分配颜色 imagecolorallocate() 可以把颜色填充到区域中,不能直接填充画布? //区域填充 bo ...
- jquery效果
//隐藏显示 <!doctype html> <html lang="en"> <head> <meta charset="UT ...
- JavaScript:实现瀑布流
一.前言: 瀑布流现在是一个非常常用的布局方式了,尤其在购物平台上,例如蘑菇街,淘宝等等. 二.流程: 1.在html文件中写出布局的元素内容: 2.在css文件中整体对每一个必要的元素进行样式和浮动 ...
- JavaScript:JavaScript事件的处理
JavaScript事件处理 —————事件的处理流程: —————动态事件绑定: —————常用的事件处理. 1.事件的概念 在页面之中,会针对用户的每一个操作进行记录.在页面中的事件可以简单的理解 ...
- 多台CentOS服务器时间同步(NTP时间同步)(转)
1.用ntpdate从时间服务器更新时间 如果你的linux系统根本没有ntpdate这个命令 yum install ntp 安装完了之后,你不要做什么配置,也不需要,直接测试一下 [root@lo ...
- ESXI
ESXI设置时间 esxi设置时间命令:Usage: esxcli system time set [cmd options] Description: set ...