<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0"
    xmlns:dc="http://purl.org/dc/elements/1.1/"
     xmlns:admin="http://webns.net/mvcb/"
     xmlns:content="http://purl.org/rss/1.0/modules/content/"
     xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
	<channel> 

	<title>Comments on: Search and Replace across entire website</title>
	<link>http://ask.metafilter.com/55734/Search-and-Replace-across-entire-website/</link>
	<description>Comments on Ask MetaFilter post Search and Replace across entire website</description>
	<pubDate>Thu, 25 Jan 2007 10:39:20 -0800</pubDate>
	<lastBuildDate>Thu, 25 Jan 2007 10:39:20 -0800</lastBuildDate>
	<language>en-us</language>
	<docs>http://blogs.law.harvard.edu/tech/rss</docs>
	<ttl>60</ttl>

	<item>
		<title>Question: Search and Replace across entire website</title>
		<link>http://ask.metafilter.com/55734/Search-and-Replace-across-entire-website</link>	
		<description>I need to do a massive replace of Flash object HTML code throughout an entire site. I really don&apos;t want to download each page and fix it by hand. &lt;br /&gt;&lt;br /&gt; I have the task of fixing the &quot;&lt;a href=&quot;http://blog.deconcept.com/2005/12/15/internet-explorer-eolas-changes-and-the-flash-plugin/&quot;&gt;Eolas bug&lt;/a&gt;&quot; in a small-to-medium sized web site. The fix involves replacing every single instance of 6 lines of embed/object code with the &lt;a href=&quot;http://blog.deconcept.com/swfobject/&quot;&gt;SWFObject&lt;/a&gt; code. I do other site changes in Dreamweaver 8, but I don&apos;t think it&apos;s up to doing a search and replace in 50 to 100 pages (at least not without downloading and reuploading every page).&lt;br&gt;
&lt;br&gt;
I have SSH access to the server, so I believe I can do some sort of regex replace magic - but I only know enough to be dangerous. &lt;strong&gt;Any instructions for replacing HTML code, only in .html files, with other specific code via regular expressions? &lt;/strong&gt; If there&apos;s a better way to do this, Id love to hear that too.&lt;br&gt;
&lt;br&gt;
I really, really don&apos;t need this to turn into a &quot;oh, regular expressions really &lt;em&gt;do&lt;/em&gt; need the brackets escaped&quot; experience.</description>
		<guid isPermaLink="false">post:ask.metafilter.com,2007:site.55734</guid>
		<pubDate>Thu, 25 Jan 2007 10:20:11 -0800</pubDate>
		<dc:creator>niles</dc:creator>
		
			<category>find</category>
		
			<category>search</category>
		
			<category>replace</category>
		
			<category>website</category>
		
			<category>ssh</category>
		
			<category>dreamweaver</category>
		
	</item> <item>
		<title>By: condour75</title>
		<link>http://ask.metafilter.com/55734/Search-and-Replace-across-entire-website#838835</link>	
		<description>Opening an html file with an old-school flash object / embed in it, in dreamweaver 8, will automatically prompt you to replace the code with Macromedia&apos;s workaround.  While it&apos;s not exactly fun to open 100 files, it&apos;d probably take all of a half hour to do the fixes this way.  Otherwise, i&apos;d use dreamweaver&apos;s regex, unless there&apos;s some specific reason this particular code needs more TLC than that.&lt;br&gt;
&lt;br&gt;
Is it always the same flash piece, or will the code differ on a page by page basis?</description>
		<guid isPermaLink="false">comment:ask.metafilter.com,2007:site.55734-838835</guid>
		<pubDate>Thu, 25 Jan 2007 10:39:20 -0800</pubDate>
		<dc:creator>condour75</dc:creator>
	</item><item>
		<title>By: Rhomboid</title>
		<link>http://ask.metafilter.com/55734/Search-and-Replace-across-entire-website#838853</link>	
		<description>&lt;tt&gt;find /path/to/files -iname \*.html | xargs perl -i.bak -pe &apos;s,your_regexp_here,replace,ig&apos;&lt;/tt&gt;&lt;br&gt;
&lt;br&gt;
That will change all *.html files in-place, making a backup copy with the extension .bak.</description>
		<guid isPermaLink="false">comment:ask.metafilter.com,2007:site.55734-838853</guid>
		<pubDate>Thu, 25 Jan 2007 10:59:25 -0800</pubDate>
		<dc:creator>Rhomboid</dc:creator>
	</item><item>
		<title>By: jouke</title>
		<link>http://ask.metafilter.com/55734/Search-and-Replace-across-entire-website#838854</link>	
		<description>If it&apos;s well-formed XHTML you might analyse the exact transformation that has to be done for every page and write a little bit of XSL that expresses that transformation.&lt;br&gt;
Then use a bit of programming code to scan all the files and apply the XSL.</description>
		<guid isPermaLink="false">comment:ask.metafilter.com,2007:site.55734-838854</guid>
		<pubDate>Thu, 25 Jan 2007 11:01:27 -0800</pubDate>
		<dc:creator>jouke</dc:creator>
	</item><item>
		<title>By: Rhomboid</title>
		<link>http://ask.metafilter.com/55734/Search-and-Replace-across-entire-website#838860</link>	
		<description>Oh, and if any of your filenames will have spaces in them, then you need:&lt;br&gt;
&lt;br&gt;
&lt;tt&gt;find /path/to/files -iname \*.html &lt;b&gt;-print0&lt;/b&gt; | xargs &lt;b&gt;-0&lt;/b&gt; perl -i.bak -pe &apos;s,your_regexp_here,replace,ig&apos;&lt;/tt&gt;&lt;br&gt;
&lt;br&gt;
And, if you want to do multiline search/replace, then you can do something like this:&lt;br&gt;
&lt;br&gt;
&lt;tt&gt;find /path/to/files -iname \*.html -print0 | xargs -0 perl -i.bak -e &apos;local $/; while(&amp;lt;&amp;gt;) { s,search line 1\nsearch line2\n,replace line1\nreplace line2\n,sig; print; }&apos;&lt;/tt&gt;</description>
		<guid isPermaLink="false">comment:ask.metafilter.com,2007:site.55734-838860</guid>
		<pubDate>Thu, 25 Jan 2007 11:05:43 -0800</pubDate>
		<dc:creator>Rhomboid</dc:creator>
	</item><item>
		<title>By: niles</title>
		<link>http://ask.metafilter.com/55734/Search-and-Replace-across-entire-website#838868</link>	
		<description>condour: No dice on the automatic changes. It&apos;ll also take me longer than a half-hour - our network speed here isn&apos;t winning any races.&lt;br&gt;
&lt;br&gt;
It is the same code on each page (I have that much going for me)&lt;br&gt;
&lt;br&gt;
Rhomboid: That&apos;s about what I&apos;m looking for, and the backup thing is nice. Now that I have actual command names, I should be able to pull this off. &lt;br&gt;
&lt;br&gt;
jouke: That scares me slightly more than regular expressions.&lt;br&gt;
&lt;br&gt;
----&lt;br&gt;
on preview: &lt;br&gt;
Yeah, that&apos;s the one problem: as this is HTML, this will be multi-line stuff. Is that bad?&lt;br&gt;
&lt;br&gt;
I might just need to take 2 hours and do this in Dreamweaver before I make a datacenter explode with my almost-but-not-quite knowledge...</description>
		<guid isPermaLink="false">comment:ask.metafilter.com,2007:site.55734-838868</guid>
		<pubDate>Thu, 25 Jan 2007 11:13:28 -0800</pubDate>
		<dc:creator>niles</dc:creator>
	</item><item>
		<title>By: Rhomboid</title>
		<link>http://ask.metafilter.com/55734/Search-and-Replace-across-entire-website#838879</link>	
		<description>If you are worried, make a quick tar archive (&lt;tt&gt;cd /path/to/top/directory &amp;amp;&amp;amp; tar cjvf ~/backup.tar.bz2 *&lt;/tt&gt;) of the whole tree as backup, so that worst case you can just untar everything.&lt;br&gt;
&lt;br&gt;
Regarding multiline search/replace, it&apos;s certainly doable with the &quot;local $/&quot; idiom.  This tells perl to snarf the whole file, so your s//g applies to the entire file.  By using the -s modifier you can match multiple lines easily.  A useful tip is to use &quot;\s+&quot; anywhere you would have whitespace: this will match spaces, tabs, newlines, etc.  So if you use this everywhere there is whitespace in your RE it will match with some flexibility.&lt;br&gt;
&lt;br&gt;
For example, &quot;foo\s+bar\s+baz\s+&quot; matches&lt;br&gt;
&lt;br&gt;
foo bar baz&lt;br&gt;
&lt;br&gt;
as well as&lt;br&gt;
&lt;br&gt;
foo&lt;br&gt;
bar&lt;br&gt;
baz&lt;br&gt;
&lt;br&gt;
as well as&lt;br&gt;
&lt;br&gt;
foo&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;bar&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;baz&lt;br&gt;
&lt;br&gt;
..and so on.  The linebreaks/indentations are all eaten equally by \s+.</description>
		<guid isPermaLink="false">comment:ask.metafilter.com,2007:site.55734-838879</guid>
		<pubDate>Thu, 25 Jan 2007 11:25:07 -0800</pubDate>
		<dc:creator>Rhomboid</dc:creator>
	</item><item>
		<title>By: grumblebee</title>
		<link>http://ask.metafilter.com/55734/Search-and-Replace-across-entire-website#838902</link>	
		<description>You have Dreamweaver? Check out its great Find/Replace (on the Edit menu). You can batch replace text (and code) in multiple files.</description>
		<guid isPermaLink="false">comment:ask.metafilter.com,2007:site.55734-838902</guid>
		<pubDate>Thu, 25 Jan 2007 11:51:02 -0800</pubDate>
		<dc:creator>grumblebee</dc:creator>
	</item><item>
		<title>By: misterbrandt</title>
		<link>http://ask.metafilter.com/55734/Search-and-Replace-across-entire-website#839391</link>	
		<description>Don&apos;t apply changes to the live site, dude. You&apos;re just asking for trouble. Just use DW&apos;s find/replace, which is pretty powerful (and yet also quite intuitive) on the local &quot;site&quot; and then reupload (but not using DW&apos;s painful FTP dealie), preferably with a smart FTP app that only syncs changed files.&lt;br&gt;
&lt;br&gt;
Or make a few local copies of the site and try your hand at the regex.</description>
		<guid isPermaLink="false">comment:ask.metafilter.com,2007:site.55734-839391</guid>
		<pubDate>Thu, 25 Jan 2007 19:04:52 -0800</pubDate>
		<dc:creator>misterbrandt</dc:creator>
	</item><item>
		<title>By: fishfucker</title>
		<link>http://ask.metafilter.com/55734/Search-and-Replace-across-entire-website#839421</link>	
		<description>seconding misterbrandt. &lt;br&gt;
&lt;br&gt;
In most cases I&apos;d recommend &quot;working smarter, not harder&quot;, but when you&apos;re looking at potentially corrupting up to 100 (presumedly static) pages, I&apos;d go the long and careful route. Download the site to your local disk, use Dreamweaver&apos;s Search And Replace (the batch search and replace only works locally anyways, if I recall correctly), and then upload during off hours (if possible). &lt;br&gt;
&lt;br&gt;
While you&apos;re at it I would *seriously* consider using some sort of include, if that option is available to you -- that way next time these sorts of changes will be *MUCH* less painful. &lt;br&gt;
&lt;br&gt;
There is a plugin for DW8 that supposedly &quot;fixes&quot; the Eolas problem, but I cannot confirm if it does so automatically. I&apos;ve always used SWFObject to fix the issue.</description>
		<guid isPermaLink="false">comment:ask.metafilter.com,2007:site.55734-839421</guid>
		<pubDate>Thu, 25 Jan 2007 19:32:08 -0800</pubDate>
		<dc:creator>fishfucker</dc:creator>
	</item><item>
		<title>By: niles</title>
		<link>http://ask.metafilter.com/55734/Search-and-Replace-across-entire-website#839883</link>	
		<description>So, here&apos;s what I&apos;m doing then: I downloaded the entire site last night, and I&apos;m going to be running Dreamweaver&apos;s S&amp;amp;R across it today, and then upload later today, which I guess I&apos;ll use FileZilla for.&lt;br&gt;
&lt;br&gt;
The main reason I thought of fixing this over SSH is because I read an article on the powers of perl in situations like this. Of course, the article (never to be found again) was concerned with changing simple things like a company name throughout a site, not nasty HTML. It turns out just because I can use wget in Ubuntu and regular expressions in Visual Studio doesn&apos;t mean I can do this!&lt;br&gt;
&lt;br&gt;
fishfucker: Yes, I know includes would be amazing, but I have inherited this site, and changes like that would be more trouble that it&apos;s worth in the long run. This site is a fun mix of good design, with a couple issues that I (expert I am not) have known to avoid for ages.&lt;br&gt;
&lt;br&gt;
&lt;br&gt;
So, thanks for all the answers everyone, and convincing me I&apos;m not quite a *n*x guru yet :) &lt;br&gt;
Long and careful it is.</description>
		<guid isPermaLink="false">comment:ask.metafilter.com,2007:site.55734-839883</guid>
		<pubDate>Fri, 26 Jan 2007 09:14:06 -0800</pubDate>
		<dc:creator>niles</dc:creator>
	</item><item>
		<title>By: niles</title>
		<link>http://ask.metafilter.com/55734/Search-and-Replace-across-entire-website#911541</link>	
		<description>&lt;small&gt;Followup:&lt;/small&gt;&lt;br&gt;
Ironically enough,  my place of work is changing its name, and I have to do this all over again. This time, at least, it&apos;s only domain names, which regex seems to be happy with.</description>
		<guid isPermaLink="false">comment:ask.metafilter.com,2007:site.55734-911541</guid>
		<pubDate>Fri, 13 Apr 2007 11:17:48 -0800</pubDate>
		<dc:creator>niles</dc:creator>
	</item>
	</channel>
</rss>
