sh 使用sed和Find查找和替换

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了sh 使用sed和Find查找和替换相关的知识,希望对你有一定的参考价值。

#Standalone command
sed -i 's/old string/new string/g' /home/dude/text-file.txt

## use a custom separator
sed -i 's:old/folder/path:new/folder/path:g' /home/dude/text-file.txt

## dry run
sed 's/old string/new string/g' | less
# Combined with find command to search and replace strings inside multiple files
sudo find /var/www/example.com/public_html -type f -exec sed -i 's/old string/new string/g' {} \;
sudo find /var/www/example.com/public_html -type f -exec sed -i 's:old/folder/path:new/folder/path:g' {} \;
sudo find /etc/td-agent/config.d/ -type f -exec sed -i 's:192.168.0.1:192.168.0.2:g' {} \;

以上是关于sh 使用sed和Find查找和替换的主要内容,如果未能解决你的问题,请参考以下文章