Удаление UTF-8 BOM из консоли

linux (debian)
find путь/к/лайвстриту/ -type f \( -name '*.tpl' -o -name '*.php' \) -exec sed -i '1 s/^\xef\xbb\xbf//' {} \;

freebsd (7.2)
find ./ -type f \( -name '*.tpl' -o -name '*.php' \) -exec sed -i -e '1 s/^\xef\xbb\xbf//' {} \;

sed почему-то иногда не отрабатывает, поэтому php, find, awk, xargs:
php -r "ob_start();
passthru('find ./ -type f \( -name \'*.tpl\' -o -name \'*.php\' \) -print0 | xargs -0r awk \'/^\xEF\xBB\xBF/ {print FILENAME}{nextfile}\'');
foreach(array_filter(explode(\"\n\",ob_get_clean())) as \$f){
        echo \"remove BOM from \$f...\n\";
        file_put_contents(\$f, substr(file_get_contents(\$f), 3));
};"
comments powered by Disqus

0 комментариев

Оставить комментарий