ubuntu下文档中查找并替换字符串举例

find /home/HBG/SegNet/CamVid -name test1.txt | xargs sed -i 's#/SegNet/CamVid/#/home/HBG/SegNet/CamVid/#g'

将路径/home/HBG/SegNet/CamVid下的文档test1.txt中的字符串 /SegNet/CamVid/ 替换为 /home/HBG/SegNet/CamVid/

注:1.#作为分隔符,此中间出现的/不会作为分隔符

      2.如果没有g,则只处理文件的第一行,有则代表处理整个文件(全部替换)


通常用法:

find 文件所在路径 -name 文件名 | xargs sed -i 's/原字符串/替换字符串/g'

猜你喜欢

转载自blog.csdn.net/u013132480/article/details/79100994