LoginSignup
27
27

More than 5 years have passed since last update.

キーワードを含んだ複数ファイルの文字列を一括置換

Posted at

ディレクトリ配下にあるファイルに記述されている文字列 hogebar に置換する場合。

block_replacement_for_multi_files.sh
find . -type f -print | xargs grep -l hoge | xargs sed -i "s/hoge/bar/g" ;

find . -type f -print
カレントディレクトリ内の相対パスを含むファイル名をリストアップ。

xargs grep -l hoge
hogeを含むファイルに絞り込む。
このコマンドは必要ないかも。
でも、sedに流し込むファイル名は置換対象ファイルのみに絞りたかったので入れている。

xargs sed -i "s/hoge/bar/g"
hogebar に置換。

27
27
3

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
27
27