LoginSignup
9
7

More than 5 years have passed since last update.

カレントディレクトリのサブディレクトリを含んだファイルの文字列を一括置換

Last updated at Posted at 2015-01-08

こんな感じで、'置換する文字列'を'置換したい文字列'に置換します。

find . -type f | xargs grep -l '置換する文字列' | xargs sed -i.bk -e 's/置換する文字列/置換したい文字列/g'

find . -type f
カレントディレクトリ及びそのサブディレクトリからファイル名を取得。

xargs grep -l '置換する文字列'
'置換する文字列'を含んだファイル名を抽出。

xargs sed -i.bk -e 's/置換する文字列/置換したい文字列/g'
抽出したファイルに含まれている'置換する文字列'を'置換したい文字列'に置換。
-i.bkこのオプションで、置換するときにバックアップファイルを作成します。
バックアップが必要ない場合は-iだけでOK。

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