Page 1 of 1

Extending the capability of Search/replace list from file

Posted: Fri Mar 21, 2014 11:02 pm
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

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

Posted: Mon Mar 24, 2014 12:27 pm
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.

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

Posted: Tue Mar 25, 2014 2:48 am
by dfhtextpipe
I will check that out.