Extending the capability of Search/replace list from file

Get help with installation and running here.

Moderators: DataMystic Support, Moderators, DataMystic Support, Moderators, DataMystic Support, Moderators

Post Reply
dfhtextpipe
Posts: 986
Joined: Sun Dec 09, 2007 2:49 am
Location: UK

Extending the capability of Search/replace list from file

Post by dfhtextpipe »

The following suggestion relates to using an external file for the replace list.

It matters not for this purpose whether the file is Excel, tab or CSV format.
For convenience, I can assume that tab delimited will be used.
In any case, one can always paste & copy from an Excel worksheet to make a tab delimited text file.

The proposed extension is this:
Do not limit the replacement to a single column or field.

The search pattern will always remain as the first column.
Yet there are some distinct benefits to be gained by permitting a multi-column or multi-field replacement.

Example:

Suppose you have a set of files in which one line contains the following:

\id XXX

where XXX is different for each file.

Now suppose you wish to insert a different set of lines for each file, but each set will depend on the value of XXX.

The replacement file might look like this: (using \t here to denote a tab delimiter)

Code: Select all

GEN\tGEN\t\\h Genesis\t\\toc1 Genesis\t\\toc2 The first Book of Moses\t\\toc3 Gen. 
EXO\tEXO\t\\h Exodus\t\\toc1 Exodus\t\\toc2 The second Book of Moses\t\\toc3 Exo.
...
etc
The reason for the second column being identical to the first will become obvious later.
The double backslashes assume the replacement type is Perl.

One can then follow the above replace filter by a simple search replace
  • with one entry:
    \t,\n
    (I am assuming CSV notation here)
    i.e. Replace tabs by a new line (assume e.g. Unix style EOLs)

    This changes the first multi-column replacement to a multi-line insertion, customised to suit each different file.

    The first file would end up like this:

    Code: Select all

    \id GEN
    \h Genesis
    \toc1 Genesis
    \toc2 The first Book of Moses
    \toc3 Gen. 
    The second would end up like this:

    Code: Select all

    \id EXO
    \h Exodus
    \toc1 Exodus
    \toc2 The second Book of Moses
    \toc3 Exo.
    and so on.

    This would be a powerful enhancement to the search/replace filter.

    It would also be a significant simplification for users who have this kind of requirement.
    Only one external file needs to be maintained, rather than a separate two column file for each replacement.

    The help for this filter would need to explain the enhancement.

    Best regards,

    David
David
User avatar
DataMystic Support
Site Admin
Posts: 2227
Joined: Mon Jun 30, 2003 12:32 pm
Location: Melbourne, Australia
Contact:

Re: Extending the capability of Search/replace list from fil

Post by DataMystic Support »

Hi David,
Do not limit the replacement to a single column or field.
AFAIK, if you use quotes around the search or replace field (in either csv or tab mode), then the replace field should be correctly parsed even with multiple lines.

Please let me know if I am wrong here.

Also, an Excel cell can contain newlines too - so I believe this works as is.
dfhtextpipe
Posts: 986
Joined: Sun Dec 09, 2007 2:49 am
Location: UK

Re: Extending the capability of Search/replace list from fil

Post by dfhtextpipe »

I will check that out.
David
Post Reply