簡體   English   中英

使用sed替換多個文件中的多行

[英]Using sed to replace multiple lines in multiple files

我有成千上萬個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文件?

先感謝您!

ls |xargs sed -i 's/google_ad_channel = "1013717472xx"/google_ad_channel = "new_code"/g'

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM