如何使用bash递归地将多个文件中的字符串替换为另一个?
我需要编写一个脚本,将目录及其所有子目录中所有文件中出现的某个字符串替换为“replaceWithThisNewString”。 怎么做呢?试试这句话:如何使用bash递归地将多个文件中的字符串替换为另一个?,bash,bash4,Bash,Bash4,我需要编写一个脚本,将目录及其所有子目录中所有文件中出现的某个字符串替换为“replaceWithThisNewString”。 怎么做呢?试试这句话: find /aDir -type f |xargs sed -i 's/certainString/replaceWithThisNewString/g' 试试这句话: find /aDir -type f |xargs sed -i 's/certainString/replaceWithThisNewString/g' 或者如果您的查找
find /aDir -type f |xargs sed -i 's/certainString/replaceWithThisNewString/g'
试试这句话:
find /aDir -type f |xargs sed -i 's/certainString/replaceWithThisNewString/g'
或者如果您的查找
不支持\+
:
find /path/to/dir -type f -exec sed -i 's/original/replacement/g' {} \;
或者如果您的查找
不支持\+
:
find /path/to/dir -type f -exec sed -i 's/original/replacement/g' {} \;
使用:
使用:
Ḧm、 如果走
xargs
路线,我会使用find-打印0 | xargs-0…
只是为了安全。Ḧm、 如果走xargs
路线,我会使用find-打印0 | xargs-0…
只是为了安全。