A shell script might work for you with a little sed. Here's a quick
hack I use. I would test on some sample areas before doing anything
important though. Assume you have a bunch of html files and want to
change the word "old" to "new". You would do this:

sar "old" "new" "*.html"

the quotes are needed. Here's the script:

<---------------- begin cut ------------------------->

#!/bin/ksh
#----------------------------------------------------------------------
# File Name:   sar
# Description: This file allows the user to search and replace a
string
#              in a bunch of files.
#
#              when using wildcards for the filename, place in quotes
#
#                     example: sar "old" "new" "*.c"
#
#----------------------------------------------------------------------

search=$1
replace=$2
files=$3

for file in "$files"
do
        cp $file $file.bak
        sed "s/$search/$replace/g" $file > tempsar
        mv tempsar $file
done


<---------------- end cut ------------------------->

The script backs the file up first. You would save this to a text
file, "sar" and make it executable (chmod +x sar).  This is obviously
EXTREMELY simple with no error checking but I thought I would throw it
out here as a starting point as there were no replies yet.

Mark

On Jun 16, 2:05 pm, BBunny <fran...@cherman.com> wrote:
> Still hoping for a response...
>
> On May 29, 12:06 am, BBunny <fran...@cherman.com> wrote:
>
> > Can anyone suggest a grep search/replace or other technique for changing
> > root-relative links of a Web site to document-relative? The site is
> > site-root is identified in BBEdit's preferences as a Web site. There's a
> > utility written to do this for a very early version of Dreamweaver (it will
> > also change all document-relative links to root-relative, if that's desired,
> > which it isn't), and it works, but only on the open document. The sitewide
> > feature doesn't work. My site has nearly 3,000 html files, so opening each
> > document and running the script would be extremely time-consuming, and the
> > author is not going to update the script. I do not know javascript and I'm
> > not that savvy with regular expressions either, so I would appreciate any
> > suggestions for running a script like this sitewide in BBEdit.
>
> > Thanks.
>
> > For reference, the Dreamweaver utility is supposed to use this regex to
> > select the files sitewide:
>
> > .+\.html?$
>
> > And it uses this script (which works, but only in the open document):
>
> > /*******************************************/
>
> > /* Change links to document/root relative. */
>
> > /* Version 1.5.1 (28 Dec 2005) */
>
> > /* Jason Dalgarno <ja...@e7x.com> */
>
> > /*******************************************/
>
> > /*
>
> > * Copyright (C) 2005 Jason Dalgarno <ja...@e7x.com>
>
> > *
>
> > * This library is free software; you can redistribute it and/or modify it
> > under
>
> > * the terms of the GNU Lesser General Public License as published by the
> > Free
>
> > * Software Foundation; either version 2.1 of the License, or (at your
> > option)
>
> > * any later version.
>
> > *
>
> > * This library is distributed in the hope that it will be useful, but
> > WITHOUT
>
> > * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
> > FITNESS
>
> > * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for
> > more
>
> > * details.http://www.gnu.org/licenses/lgpl.txt
>
> > */
>
> > function canAcceptCommand()
>
> > {
>
> > var sr, doc;
>
> > sr = dreamweaver.getSiteRoot();
>
> > doc = dreamweaver.getDocumentDOM('document');
>
> > /*
>
> > * If a site is defined, the document has been saved, the document is saved
>
> > * in a defined site and the document is HTML.
>
> > */
>
> > return (sr && doc && doc.URL && doc.URL.indexOf(sr) == 0 && fileIsHTML(doc)
> > && !hasBaseHref(doc)) ? true : false;
>
> > }
>
> > function commandButtons()
>
> > {
>
> > return Array('Document relative', 'initRelativity("document", "document")',
>
> > 'Root relative', 'initRelativity("document", "root")',
>
> > 'Absolute (http://...)', 'initRelativity("document", "absolute")',
>
> > 'Sitewide - Document relative', 'initRelativity("site", "document")',
>
> > 'Sitewide - Root relative', 'initRelativity("site", "root")',
>
> > 'Get latest version', 'fetchLatest()',
>
> > 'Cancel', 'window.close()',
>
> > 'Help', 'relativityHelp()');
>
> > }
>
> > function relativityHelp()
>
> > {
>
> > dreamweaver.browseDocument(dreamweaver.getConfigurationPath() +
> > '/Shared/JSN/relativity/help.htm');
>
> > }
>
> > /**
>
> > * Check if the current document/file is a HTML document
>
> > *
>
> > * @param object Document
>
> > * @return boolean True is file is an html document, false if not.
>
> > */
>
> > function fileIsHTML(doc)
>
> > {
>
> > /*
>
> > * .search(/<html/i) is to allow for <HTML> in uppercase.
>
> > *
>
> > * Relativity cannot work on a partial document that is included elsewhere
>
> > * by SSI or PHP (for example) as it will not be able to resolve the base
>
> > * URL correctly.
>
> > */
>
> > return doc.getParseMode() == 'html' &&
> > doc.documentElement.outerHTML.search(/<html/i) != -1;
>
> > }
>
> > /**
>
> > * If a file has a <base href="..." /> do not modify links
>
> > *
>
> > * @param object Document
>
> > * @return boolean True if file has base href, false if we can safely modify
> > it
>
> > */
>
> > function hasBaseHref(doc)
>
> > {
>
> > var base, i, ret = false;
>
> > base = doc.getElementsByTagName('BASE');
>
> > for (i = 0; i < base.length; ++i) {
>
> > if (base[i].href) {
>
> > ret = true;
>
> > break;
>
> > }
> > }
>
> > return ret;
>
> > }
>
> > /**
>
> > * Read updater file from remote server and check version numbers
>
> > */
>
> > function fetchLatest()
>
> > {
>
> > /*
>
> > * remote file goes like this:
>
> > * version=1.2.3
>
> > * url=http://www.example.com/dwextension.mxp
>
> > * filename=filename_for_local_file.ext
>
> > * title=Text for download dialog title
>
> > * beforemessage=Some message to show before downloading.
>
> > * donemessage=Message to show after file has been downloaded.
>
> > */
>
> > var currentVersion, updaterUrl, versionFile, latest, pairs, i, params,
> > confirmMsg, gotUpdate;
>
> > currentVersion = '1.5.1';
>
> > updaterUrl = 'http://www.microwaved.plus.com/dw/relativityupdate.txt';
>
> > versionFile = MMHttp.getText(updaterUrl);
>
> > if (versionFile.statusCode == 200) {
>
> > latest = new Array;
>
> > pairs = versionFile.data.replace(/\r\n?/, '\n').split('\n');
>
> > for (i = 0; i < pairs.length; ++i) {
>
> > params = pairs[i].split('=');
>
> > if (params.length == 2) {
>
> > latest[params[0]] = params[1].replace(/\s+$/, '');
>
> > }
> > }
>
> > if (latest.version && latest.url && latest.filename && latest.title
>
> > && latest.beforemessage && latest.donemessage) {
>
> > latest.beforemessage = latest.beforemessage.replace(/\\n/g, '\n');
>
> > latest.donemessage = latest.donemessage.replace(/\\n/g, '\n');
>
> > if (latest.version == currentVersion) {
>
> > alert('No update available');
>
> > } else {
>
> > confirmMsg = 'Update available\n\n';
>
> > confirmMsg += 'Latest version is ' + latest.version;
>
> > confirmMsg += ' (currently using ' + currentVersion + ')\n\n';
>
> > confirmMsg += latest.beforemessage + '\n\n';
>
> > confirmMsg += 'Download the update?';
>
> > if (confirm(confirmMsg)
>
> > && (gotUpdate = MMHttp.getFile(latest.url, true, 'file:///C|/' +
> > latest.filename,
>
> > 'Download update - ' + latest.title)) && gotUpdate.statusCode) {
>
> > if (gotUpdate.statusCode == 200) {
>
> > alert('Download complete.\n\n' + latest.donemessage);
>
> > } else {
>
> > alert('Error retrieving file.')
>
> > }
> > }
> > }
> > } else {
>
> > alert('Updater file does not follow expected format. Got this instead:\n\n'
> > + pairs.join('\n'));
>
> > }
> > } else {
>
> > // 404, host not found, not online etc
>
> > alert('Updater file not found');
>
> > }
> > }
>
> > /**
>
> > * Change link relativity
>
> > *
>
> > * @param string Relativity direction, 'document' or 'root'
>
> > */
>
> > function Relativity(relativeTo)
>
> > {
>
> > var doc, ignore, ignore2, tagAttrs, siteRoot, siteUrl;
>
> > /**
>
> > * Read tag name and attributes file
>
> > */
>
> > function readTagAttributes()
>
> > { // Read tag name and attributes file
>
> > var fileContents, i, tagAttribs;
>
> > fileContents = DWfile.read(dreamweaver.getConfigurationPath()
>
> > + '/Shared/jsn/relativity/uris.txt').replace(/\r\n?/g, '\n').split(/\n/);
>
> > for (i = 0; i < fileContents.length; ++i) {
>
> > tagAttribs = fileContents[i].split(' ');
>
> > tagAttrs[tagAttribs[0]] = tagAttribs.slice(1);
>
> > }
> > }
>
> > /**
>
> > * getElementsByTagName without translated elements
>
> > *
>
> > * There are two problems with the regular getElementsByTagName
>
> > * implementation:
>
> > * 1) Translated elements are included, but DW will choke if you try to
>
> > * modify them.
>
> > * 2) Elements with a name or id attribute beginning with a number are
>
> > * inserted a second time in the array with its name as the key,
>
> > * causing the array to be longer than it should be with empty elements
>
> > * along the way. For example, if the only <a> tag in a document is
>
> > * <a name="100"></a>, doc.getElementsByTagName('A').length is 101.
>
> > *
>
> > * @param object Partial document
>
> > * @param string Tag name
>
> > * @return array Non-translated elements
>
> > */
>
> > function getElements(docPart, tag)
>
> > {
>
> > var eles, cleaned, i, offsets, hasTranslatedContent;
>
> > eles = docPart.getElementsByTagName(tag);
>
> > hasTranslatedContent = docPart.getElementsByTagName('MM:BEGINLOCK').length ?
> > true : false;
>
> > cleaned = new Array;
>
> > for (i = 0; i < eles.length && eles[i]; ++i) {
>
> > if (hasTranslatedContent) {
>
> > /*
>
> > * translated element offsets refer to translated source,
>
> > * offsetsToNode refers to actual source, if they don't match
>
> > * the element is translated
>
> > */
>
> > offsets = doc.nodeToOffsets(eles[i]);
>
> > if (doc.offsetsToNode(offsets[0], offsets[1]) == eles[i]) {
>
> > cleaned.push(eles[i]);
>
> > }
> > } else {
>
> > cleaned.push(eles[i]);
>
> > }
> > }
>
> > return cleaned;
>
> > }
>
> > /**
>
> > * Get root relative path
>
> > *
>
> > * @param string Document relative path
>
> > * @return string Root relative path
>
> > */
>
> > function toRoot(path)
>
> > {
>
> > var trailSlash, dotSlash;
>
> > if (path.substr(0, 2) == './') { // clean ./ paths
>
> > if (path.length > 2) {
>
> > path = path.substr(2);
>
> > } else {
>
> > path = 'PATHWASDOTSLASH'; // placeholder if path was just ./
>
> > dotSlash = true;
>
> > }
> > }
>
> > // remember if original path had trailing slash
>
> > trailSlash = (RegExp('/$').test(path)) ? '/' : '';
>
> > // dreamweaver.relativeToAbsoluteURL does not work as documented
>
> > path = dreamweaver.relativeToAbsoluteURL(doc.URL, siteRoot, path);
>
> > // remove everything before site root, -1 to retain leading slash
>
> > path = path.substr(siteRoot.length - 1);
>
> > path += trailSlash; // replace trailing slash if needed
>
> > if (dotSlash) {
>
> > // remove ./ placeholder
>
> > path = path.replace(/PATHWASDOTSLASH$/, '');
>
> > }
>
> > return path;
>
> > }
>
> > /**
>
> > * Get document relative path
>
> > *
>
> > * @param string Root relative path
>
> > * @return string Document relative path
>
> > */
>
> ...
>
> read more »

-- 
You received this message because you are subscribed to the 
"BBEdit Talk" discussion group on Google Groups.
To post to this group, send email to bbedit@googlegroups.com
To unsubscribe from this group, send email to
bbedit+unsubscr...@googlegroups.com
For more options, visit this group at
<http://groups.google.com/group/bbedit?hl=en>
If you have a feature request or would like to report a problem, 
please email "supp...@barebones.com" rather than posting to the group.
Follow @bbedit on Twitter: <http://www.twitter.com/bbedit>

Reply via email to