您好我想更換document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
如何使用sed替換以下文本?
與
(function() { var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);})();
...
所以我用這個下面的代碼。
find /cygdrive/c/xampp/htdocs/news -type f -exec sed -i s#document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));#(function() { var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);})();#g {} \;
但它並沒有取代。轉義有什麼問題嗎?
感謝
殼牌公司將擴大雙和單引號字符。你必須引用他們。 – fork0 2012-07-10 10:46:11
此外,「。」 (點)在正則表達式中有特殊的含義。不過,在這個特殊情況下,這不太重要。 – fork0 2012-07-10 10:47:47
@ fork0,這將無濟於事,shell也會分詞。這些空格需要轉義(或引用) – 2012-07-10 11:19:40