【发布时间】:2017-11-08 14:10:01
【问题描述】:
我有数千个 html 文件,其中有两段不同的旧 google adsense 代码需要用新代码替换。这些文件位于 linux 服务器上。
旧代码如下:
<script type="text/javascript"><!--
google_ad_client = "pub-xxx";
google_ad_width = 336;
google_ad_height = 280;
google_ad_format = "336x280_as";
google_ad_type = "text";
//2007-06-09: Forum archive rectangle
google_ad_channel = "1013717472xx";
google_color_border = "FFFFFF";
google_color_bg = "FFFFFF";
google_color_link = "0000FF";
google_color_text = "000000";
google_color_url = "000000";
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script>
我需要在代码中匹配此文本 "google_ad_channel = "1013717472xx"",将整个代码替换为新代码。
新代码如下:
<script src="https://pagead2.googlesyndication.com/pub-config/r20160913/ca-pub-xxx.js"></script><script src="http://pagead2.googlesyndication.com/pub-config/r20160913/ca-pub-xxx.js"></script><script type="text/javascript"><!--
google_ad_client = "pub-xxx";
/* frm arch linkunit 200x90, created 5/30/08 */
google_ad_slot = "0112084554";
google_ad_width = 200;
google_ad_height = 90;
//-->
</script>
<script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script>
如何使用 sed 替换我服务器上的所有 html 文件?
提前谢谢你!
【问题讨论】:
-
发布您的“新代码”。你的操作系统是什么?
-
谢谢。添加了新代码,我的操作系统是 ubuntu
-
您的“新代码”根本没有任何
google_ad_channel ="..."。令人困惑 -
文本“google_ad_channel ="..."" 是一个匹配项,一旦匹配,整个代码就会被替换。新代码中没有该术语。
-
安装 xmlstarlet 工具,然后告诉我你什么时候准备好