使用sed替换多个文件中的多行

时间:2017-06-07 09:41:22

标签: file sed replace lines

我有成千上万的html文件,其中有两个不同的旧谷歌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>

如何在服务器上的所有html文件中使用sed进行替换?

提前谢谢!

1 个答案:

答案 0 :(得分:0)

[INFO] Scanning for projects...
[INFO]                                                                         
[INFO] ------------------------------------------------------------------------
[INFO] Building firefox 1.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO] 
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ firefox ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 0 resource
[INFO] 
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ firefox ---
[INFO] Nothing to compile - all classes are up to date
[INFO] 
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ firefox ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory C:\work\verso3\src\test\resources
[INFO] 
[INFO] --- maven-compiler-plugin:3.1:testCompile (default-testCompile) @ firefox ---
[INFO] Nothing to compile - all classes are up to date
[INFO] 
[INFO] --- maven-surefire-plugin:2.20:test (default-test) @ firefox ---
[INFO] 
[INFO] -------------------------------------------------------
[INFO]  T E S T S
[INFO] -------------------------------------------------------
[INFO] Running features.FirefoxTest
[ERROR] Tests run: 1, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 0.629 s <<< FAILURE! - in features.FirefoxTest
[ERROR] open_browser(features.FirefoxTest)  Time elapsed: 0.58 s  <<< ERROR!
java.lang.NullPointerException
    at features.FirefoxTest.open_browser(FirefoxTest.java:31)

[INFO] 
[INFO] Results:
[INFO] 
[ERROR] Errors: 
[ERROR]   FirefoxTest.open_browser:31 » NullPointer
[INFO] 
[ERROR] Tests run: 1, Failures: 0, Errors: 1, Skipped: 0
[INFO] 
[ERROR] There are test failures.

Please refer to C:\work\verso3\target\surefire-reports for the individual test results.
Please refer to dump files (if any exist) [date]-jvmRun[N].dump, [date].dumpstream and [date]-jvmRun[N].dumpstream.
[INFO] 
[INFO] --- maven-jar-plugin:2.4:jar (default-jar) @ firefox ---
[INFO] Building jar: C:\work\verso3\target\firefox-1.0-SNAPSHOT.jar
[INFO] 
[INFO] --- serenity-maven-plugin:1.4.0:aggregate (serenity-reports) @ firefox ---
[INFO] current_project.base.dir: C:\work\verso3
[INFO] Generating test results for 0 tests
[INFO] 0 requirements loaded after 27 ms
[INFO] 0 related requirements found after 27 ms
[INFO] Generating test outcome reports: false
[INFO] Starting generating reports: 38 ms
[INFO] Configured report threads: 80
[INFO] Finished generating test results for 0 tests after 316 ms
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 5.337 s
[INFO] Finished at: 2017-06-08T13:20:18+03:00
[INFO] Final Memory: 17M/274M
[INFO] ------------------------------------------------------------------------

Process finished with exit code 0