linux中按路径查找并替换某字符串的命令

1.查找包含某字符串的命令,查询结果返回包含这个字符串的文件

grep -r "http:\/\/www.baidu.com\/test1\/test2\/35084580" /www/wwwroot/baidu.com

                            查找字符串内容                                                 查找路径

 2.查找包含某字符串内容并替换

sed -i "s/http:\/\/www.baidu.com\/test1\/test2\/35084580/http:\/\/www.baidu.com\/newpath1\/newpath2\/test/g" `grep -rl "http:\/\/www.baidu.com\/test1\/test2\/35084580" /www/wwwroot/baidu.com`

                       查找字符串内容                                                                    用来替换的内容                                                        查找字符串内容                                                                        查找路径 

 sed -i "s/查找字段/替换字段/g" 'grep -rl "查找字段" 路径'        

 

注意:"/"前需要加转义符"\"                 

 

posted on 2021-10-26 09:49  慢慢走~  阅读(599)  评论(0编辑  收藏  举报