需要修改多个文件的内容,一个一个的替换比较繁琐。那么有没有什么好的方法直接多多个文件进行批量修改呢?方法如下:
1. sed
grep old_string -rl ./* | xargs sed -i "s/old_string/new_string/g"文章源自运维生存时间-https://www.ttlsa.com/linux-command/batch-change-multiple-file-content/
sed -i "s/old_string/new_string/g" `grep old_string -rl ./*`文章源自运维生存时间-https://www.ttlsa.com/linux-command/batch-change-multiple-file-content/
如:文章源自运维生存时间-https://www.ttlsa.com/linux-command/batch-change-multiple-file-content/
sed -i "s/11/xxx/g" `grep 11 -rl ./*`文章源自运维生存时间-https://www.ttlsa.com/linux-command/batch-change-multiple-file-content/
grep xxxx -rl ./* | xargs sed -i "s/x/asdfadsfasdfafd/g"文章源自运维生存时间-https://www.ttlsa.com/linux-command/batch-change-multiple-file-content/
2. perl
perl -pi -e 's|old_string|new_string|g' `find ./ -type f`文章源自运维生存时间-https://www.ttlsa.com/linux-command/batch-change-multiple-file-content/
如:文章源自运维生存时间-https://www.ttlsa.com/linux-command/batch-change-multiple-file-content/
perl -pi -e 's|ISO-8859-1|UTF-8|g' `find ./ -type f`文章源自运维生存时间-https://www.ttlsa.com/linux-command/batch-change-multiple-file-content/ 文章源自运维生存时间-https://www.ttlsa.com/linux-command/batch-change-multiple-file-content/

1F
批量更新不多的文件还行,如果遇到上万个文件批量更新就不行了,会列表溢出吧,就应该用循环来解决了
B1
@ aiplaypc 情况多种多样,点明白了,面就清晰了