Lazy Diary @ Hatena Blog

PowerShell / Java / miscellaneous things about software development, Tips & Gochas. CC BY-SA 4.0/Apache License 2.0

-i オプション

  • pi.org みたいに指定して使う。次の例では、.txt なファイルの文字列 foo を bar に全て置換したうえで、元々のファイル(文字列 foo が含まれるファイル)を .txt.org にリネームしてとっておく。
$ perl -pi.org -e 's/foo/bar/g' *.txt

は、次と同義。

$ for i in *.txt; do cp $i $i.org; done
$ rm -f *.txt
$ for i in *.txt.org; do perl -p 's/foo/bar/g' > `basename $i .org`; done