Extending the capability of Search/replace list from file

Get help with installation and running here.

Moderators: DataMystic Support, Moderators

DFH
Posts: 658
Joined: Sun Dec 09, 2007 2:49 am
Location: UK

Extending the capability of Search/replace list from file

Postby DFH » Fri Mar 21, 2014 11:02 pm

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 [list] 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

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

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

Postby DataMystic Support » Mon Mar 24, 2014 12:27 pm

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.
Regards,

Simon Carter, http://DataMystic.com/forums/index.php
http://PredictBGL.com - Insulin dose calculator for Type 1 diabetes
http://DownloadPipe.com - 250,000 free software downloads
http://DetachPipe.com - send huge email attachments

DFH
Posts: 658
Joined: Sun Dec 09, 2007 2:49 am
Location: UK

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

Postby DFH » Tue Mar 25, 2014 2:48 am

I will check that out.


Return to “TextPipe Tips and Tricks, Questions and Support”

Who is online

Users browsing this forum: Baidu [Spider], Bing [Bot] and 2 guests