如何在目录树中递归地查找和替换所有出现的字符串? [英] How to find and replace all occurrences of a string recursively in a directory tree?

查看:227
本文介绍了如何在目录树中递归地查找和替换所有出现的字符串?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用grep和sed,我该如何替换所有出现的:

  a.example.com 

with

 位于 / home / user下的文本文件中的b.example.com 

/ 目录树递归地查找并替换子目录中所有文件中的所有匹配项。 试试这个: find / home / user / -type f | xargs sed -i's / a.example.com / b.example.com / g'


Using just grep and sed, how do I replace all occurrences of:

a.example.com

with

b.example.com

within a text file under the /home/user/ directory tree recursively finding and replacing all occurrences in all files in sub-directories as well.

解决方案

Try this: find /home/user/ -type f | xargs sed -i 's/a.example.com/b.example.com/g'

这篇关于如何在目录树中递归地查找和替换所有出现的字符串?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆