AWK /桑达:如何做一个递归查找/字符串替换? [英] Awk/Sed: How to do a recursive find/replace of a string?
问题描述
如何我查找和替换的每个实例:
How to I find and replace every occurrence of:
subdomainA.example.com
与
subdomainB.example.com
在 /家庭/网络/
目录树下每一个文本文件(递归查找/替换)。
in every text file under the /home/www/
directory tree (recursive find/replace).
推荐答案
注意:不包括git仓库的文件夹上运行此命令 - 修改git的可能会破坏你的git指数
Note: Do not run this command on a folder including a git repo - changes to .git could corrupt your git index.
find /home/www -type f -print0 | xargs -0 sed -i 's/subdomainA\.example\.com/subdomainB.example.com/g'
从找人
:
-print0 (GNU只能找到)告诉找到要使用的空字符的空格代替(\\ 0)作为发现路径名之间的输出分隔符。这是一个更安全的选择,如果你的文件可以包含空格或其他特殊字符。建议使用-print0参数找到,如果你使用-exec命令或xargs的(需要在xargs的-0参数)。
-print0 (GNU find only) tells find to use the null character (\0) instead of whitespace as the output delimiter between pathnames found. This is a safer option if you files can contain blanks or other special character. It is recommended to use the -print0 argument to find if you use -exec command or xargs (the -0 argument is needed in xargs.).
这篇关于AWK /桑达:如何做一个递归查找/字符串替换?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!