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
  • 相关阅读:
    expect script
    2011年11月28日,29日学习内容总结
    2011年11月27日学习内容总结
    Toad使用(转)
    2011年11月30日学习总结
    2011年11月24日学习内容总结
    2010年11月23日学习内容总结
    Toad Can't initialize OCI. Error 1解决办法
    2011年11月25日学习内容总结
    2011年12月1日学习内容总结
  • 原文地址:https://www.cnblogs.com/davidhhuan/p/3702613.html
Copyright © 2011-2022 走看看