您现在的位置是:主页 > news > 怎样申请网站域名/百度经验官网首页
怎样申请网站域名/百度经验官网首页
admin2025/4/29 20:19:56【news】
简介怎样申请网站域名,百度经验官网首页,天津地区个人网站备案,网站建设与运营 市场分析由于各种需求,我们经常要在服务器上替换多个文件中的某个指定字符串。比如在所有的php文件中,将 google.com 替换为 google.cn 或其他搜索引擎的txt文字。在本地电脑上编辑可以使用Notepad,如果在服务器上则使用linux命令行的命令进行替换则会…
由于各种需求,我们经常要在服务器上替换多个文件中的某个指定字符串。比如在所有的php文件中,将 google.com 替换为 google.cn 或其他搜索引擎的txt文字。
在本地电脑上编辑可以使用Notepad++,如果在服务器上则使用linux命令行的命令进行替换则会非常简单。具体形式如下:
一、pearl命令
perl -pi -w -e 's/search/replace/g;' *.php
-e means execute the following line of code.
-i means edit in-place
-w write warnings
-p loop
来源: http://www.liamdelahunty.com/tips/linux_search_and_replace_multiple_files.php
二、Find & Replace 命令
for fl in *.php; do
mv $fl $fl.old
sed ‘s/FINDSTRING/REPLACESTRING/g’ $fl.old > $fl
rm -f $fl.old
done
来源:http://gabeanderson.com/2008/02/01/unixlinux-find-replace-in-multiple-files/
三、Sed 命令(单文件)
sed -i 's/old-text/new-text/g' input.txt
来源:https://www.cyberciti.biz/faq/how-to-use-sed-to-find-and-replace-text-in-files-in-linux-unix-shell/
四、Sed命令(多文件)
sed ‘s/oldstring/newstring/’ “$1” > “$1”.new && find -iname “*.new” | sed ‘s/.new//’ | sh
来源:https://serverfault.com/questions/70939/how-to-replace-a-text-string-in-multiple-files-in-linux