如何在目录树中递归查找和替换所有出现的字符串? [英] How to find and replace all occurrences of a string recursively in a directory tree?
本文介绍了如何在目录树中递归查找和替换所有出现的字符串?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
仅使用 grep 和 sed,如何替换所有出现的:
Using just grep and sed, how do I replace all occurrences of:
a.example.com
与
b.example.com
在 /home/user/
目录树下的文本文件中递归查找并替换子目录中所有文件中的所有匹配项.
within a text file under the /home/user/
directory tree recursively finding and replacing all occurrences in all files in sub-directories as well.
推荐答案
试试这个:
find /home/user/ -type f | xargs sed -i 's/a.example.com/b.example.com/g'
如果你想忽略点目录
find . ( ! -regex '.*/..*' ) -type f | xargs sed -i 's/a.example.com/b.example.com/g'
搜索表达式中的转义点
这篇关于如何在目录树中递归查找和替换所有出现的字符串?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文