LoginSignup
1
2

More than 5 years have passed since last update.

Macで再起的にファイルを検索してBOMを取り除く

Posted at

BOMの入ったHTMLファイルがたくさんコミットされていて、ページが崩れていたので一気に置換しようと思ったが、なかなかうまくできなかったのでメモ残しときます。

find . -type f -print0 | xargs -0 awk '/^\xEF\xBB\xBF/ {print FILENAME} {nextfile}' | xargs perl -pi -e 's/^\xEF\xBB\xBF//g'

sedで同じファイルで上書きするのがなかなかできなくてこの辺を参考にperlを使いました。

StackOverFlowでよく見かける下記はうまく動かなかった。理由は詰めていないがMacだからかな?

find . -type f -exec sed '1s/^\xEF\xBB\xBF//' -i.bak {} \; -exec rm {}.bak \;

1
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
2