On 6/8/2011 9:04 AM, l4c wrote:
> On 06/08/2011 09:58 AM, wrote:
>> My web site has gotten badly out dated from lack of maintainence.
>> I want
>> to get it back in shape. One of the most immediate problems is that
>> (since we added a blog, and gave it the address that was the
>> address of
>> the whole web site) every "home button" in every html file instead of
>> leading back to the old "home page", leads back to the blog.
> for file in *.html; do sed -i 's/blogpage/homepage/g' $file; done
I would like to second this, but add a little more information. If
you are not experienced in sed, this may give you some issues without
Sed is a pattern matching/replacing program. Basically, the "sed -i"
command does an in-place change of the files. It reads the file,
makes a change, and writes back to the original file.
The "*for file in *.html;*" portion will find all the html files in
the current directory, and then do the sed edit on each one
individually. If you have multiple subdirectories, you will either
need to run this command on all of the subdirectories or use "find"
or something similar to do it for all of them.
The sed command itself, while fairly straight-forward, can give you
grief if you have any path-parts to your link. For example, if you
were trying to match "/Dave/blog" and replace it with
"/newpage/index.html" you will run into some issues. The "/"
character is the magical separator, and needs to be prefixed with a
back-slash. So you would need to have the sed command be:
*I am hoping that the bolded slashes show off. The bolded slashes
are the slashes that have not been escaped, and are the separators.
They designate the two sections, a "match this" section, and a
"replace it with this" section.
One problem with the sed -i solution is that it is permanent,
regardless of what you intended. There is no "undo" button. You
will want to make a backup of your files before you do it.
But, when you are simply doing a one-to-one replacement, it is a very
simple and effective thing to do. If you are struggling with this,
drop us an email with the text of the actual href you would like to
replace, and what you would like to change it to.
ChristianSource FSLUG mailing list