[TOC]
参考文档:https://www.cyberciti.biz/faq/how-to-use-sed-to-find-and-replace-text-in-files-in-linux-unix-shell/
$ cat sed/hello.txt
The is a test file created by nixCrft for demo purpose.
foo is good.
Foo is nice.
I love FOO.
$ sed 's/foo/bar/g' sed/hello.txt
The is a test file created by nixCrft for demo purpose.
bar is good.
Foo is nice.
I love FOO.
安装gnu sed
$ brew install gnu-sed
使用gsed
执行大小些不敏感替换
$ gsed 's/foo/bar/gI' sed/hello.txt
The is a test file created by nixCrft for demo purpose.
bar is good.
bar is nice.
I love bar.
$ sed -i '.bak' 's/foo/bar/g' sed/hello.txt
$ sed -i '' 's/foo/bar/g' sed/hello.txt
$ find sed -name *.txt -exec sed -i '' 's/foo/bar/g' {} \;