sed -i 's/原字符串/替换后字符串/g' `grep '搜索关键字' -rl /data/目标目录/ --include "*.html"`

  上面是递归查找目录中所有的HTML文件 把包含符合关键字的文件用sed去做替换

这里要注意如果sed要替换的字符串中如果有/ ^ ' 之类的需要用\做转义

多个替换用;分割 例如 

sed -i 's/原字符串1/替换后字符串1/g;s/原字符串2/替换后字符串2/g'

  

参考资料

http://man.linuxde.net/grep

http://blog.sina.com.cn/s/blog_5fd841bf0101dt0r.html

http://blog.csdn.net/decisiveness/article/details/45602789

https://segmentfault.com/q/1010000008293993

相关文章:

  • 2022-02-03
  • 2022-12-23
  • 2022-01-07
  • 2021-12-31
  • 2022-12-23
  • 2022-01-07
  • 2021-04-28
  • 2022-12-23
猜你喜欢
  • 2021-12-31
  • 2021-12-31
  • 2021-10-15
  • 2021-12-31
  • 2022-12-23
  • 2022-02-18
  • 2022-03-06
相关资源
相似解决方案