Batch search & replace according to a text file

Subject: Batch search & replace according to a text file
From: Sandy Harris <sandyinchina -at- gmail -dot- com>
To: techwr-l -at- lists -dot- techwr-l -dot- com
Date: Fri, 25 Nov 2005 07:03:08 +0800

Geoff Lane <geoff -at- gjctech -dot- co -dot- uk> wrote:

> ... Broberg, Mats wrote;
>
> > Dear all,
>
> > I need to search for approx. 250 different expressions in each and
> > one of approx. 5,000 different XML files. For each match, I need the
> > function to replace the expression with another expression that can
> > be specified in an external text file (where also each original
> > expression is stated). The expression is an if-clause that is
> > surrounded by special tags, so there is no risk expressions in the
> > body text will be replaced.
>
> > I suppose this could be done by a script or something like that? Any
> > script experts out there?
> ---
>
> This should be straightforward in VBScript, VBA, PHP, and a few other
> languages. For VBScript and VBA, check out the FileSystemObject
> object, Folder and File objects, and their properties and methods.
>
Unix (hence Linux) has had 'sed', the stream editor, since the 70s.
It reads an input file, applies the editing commands, and writes an
output file with the changed text. Simple commands can be
provided on the command line. Alternately, you can tell it to read
commands from a file.

A typical command might look like this:

/^[0-9]/s/Fred/&eric/

/^[0-9]/ is a pattern matching test. The command will be applied
only to lines that match the pattern, here to lines beginning (^)
with a digit ([0-9]).

The rest is the command, s is substitute and the whole thing
replaces Fred with Frederic.

For more complex text processing, languages like awk (also
on all Unix systems) or PERL (on nearly all modern Unix, and
readily available, free, for Windows). or PHP or ... will do the
job.
--
Sandy Harris
Zhuhai, Guangdong, China


--
Sandy Harris
Zhuhai, Guangdong, China
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Now Shipping -- WebWorks ePublisher Pro for Word! Easily create online
Help. And online anything else. Redesigned interface with a new
project-based workflow. Try it today! http://www.webworks.com/techwr-l

Doc-To-Help 2005 now has RoboHelp Converter and HTML Source: Author
content and configure Help in MS Word or any HTML editor. No
proprietary editor! *August release. http://www.componentone.com/TECHWRL/DocToHelp2005

---
You are currently subscribed to TECHWR-L as archive -at- infoinfocus -dot- com -dot-

To unsubscribe send a blank email to
techwr-l-unsubscribe -at- lists -dot- techwr-l -dot- com
or visit http://lists.techwr-l.com/mailman/options/techwr-l/archive%40infoinfocus.com

Send administrative questions to lisa -at- techwr-l -dot- com -dot- Visit
http://www.techwr-l.com/techwhirl/ for more resources and info.


References:
Batch search & replace according to a text file: From: Broberg, Mats
Re: Batch search & replace according to a text file: From: Geoff Lane

Previous by Author: Fwd: front matter in manuals
Next by Author: Re: A prescriptive language?
Previous by Thread: Re: Batch search & replace according to a text file
Next by Thread: Chautauqua and 3-D?


What this post helpful? Share it with friends and colleagues:


Sponsored Ads