zoukankan      html  css  js  c++  java
  • [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 $'xEFxBBxBF'  /home/rootfolder/Yii_project  > file_with_boms.txt

    3) Now, Run this one

    while read l; do sed -i '1 s/^xefxbbxbf//'  $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/	/    /g' {} ; && grep -rl $'xEFxBBxBF'  /path/to/your/folder  > file_with_boms.txt && while read l; do sed -i '1 s/^xefxbbxbf//'  $l; done < file_with_boms.txt && rm file_with_boms.txt
  • 相关阅读:
    MYSQL中replace into的用法以及与inset into的区别
    怎么安装phpcms?PHPCMS V9安装图文教程
    Yii 框架生成缩略图
    怎么让普通用户使用root权限执行用户命令
    自学Linux命令的四种方法
    最完整PHP.INI中文版
    前端chrome浏览器调试
    phpstorm快捷键记录
    客户关系管理
    Subquery returns more than 1 row
  • 原文地址:https://www.cnblogs.com/davidhhuan/p/3702613.html
Copyright © 2011-2022 走看看