u16suzuの blog

日々学んだことのメモブログです。

まとめてファイル置換する

  • hoge ディレクトリの中にある.rbファイル中にある文字列 foobarに置換する。

    -i "0" を指定することでバックアップファイルを作らないようになる。

$ find ./hoge -type f -name "*.rb" -print0 | xargs -0 sed -i "" -e "s/foo/bar/g"
  • Redis.new.flushall を含む行全てを削除する。
$ find ./spec/ -type f -name "*.rb" -print0 | xargs -0 sed -i "" -e "/Redis.new.flushall/d"