> shell编程 >

shell 脚本替换文件中的某个字符串

1、将当前目录下包含"qwe"串的文件中的"qwe"字符串替换为"abc"

sed -i "s/qwe/abc/g" `grep "qwe" -rl ./`


2、将某个文件中的"qwe"字符串替换为"abc"

sed -i "s/qwe/abc/g" test.txt


如果将某个文件中以"qwe"开头的字符串修改为“abc”:

sed -i "s/qwe*/abc/g" test.txt



(责任编辑:IT)