I have a bunch of files with some old google tracking code at the bottom of the page:
<script type="text/javascript"> var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www."); document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E")); </script> <script type="text/javascript"> try { var pageTracker = _gat._getTracker("UA-XXXXXXXXX-1"); pageTracker._trackPageview(); } catch(err) {}</script>
I need to update that so that it has the new version of the GA code:
<script type="text/javascript"> var _gaq = _gaq || []; _gaq.push(['_setAccount', 'UA-xxxxxxx-1']); _gaq.push(['_setDomainName', 'site.com']); _gaq.push(['_trackPageview']); (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); })(); </script>
Normally I would use find . -name "*html" -exec sed s/find/replace/ {} \;
to do this, but from what I understand it can't handle multi lines. How do I modify something like this to do a find and replace for multi lines, and how do I easily deal with all that stuff I'd have to escape at the command line? I'm not against creating a bash file.
I am also not against putting the "find" and "replace" stuff in text files and then pulling it into the command that way - at least that should make the escaping part easier.
Thanks!