ADV: filePro Global Search and Replace is here!
Fairlight
fairlite at fairlite.com
Tue Sep 25 21:32:44 PDT 2012
On Tue, Sep 25, 2012 at 06:17:40PM -0400, J. P. Radley thus spoke:
>
> What happens if the original string is a substring of something in the
> processing table?
>
> Suppose I have lines that read:
>
> lookup george k=2 i=a -nx
> lookup georgetown k=4 i-c -nx
>
> and I ask to change "george" to "york".
>
> Will "georgetown" morph to "yorktown"? Or must the original string be
> surrounded by a pair of spaces or a pair of quotes or parentheses?
Well, v01.01.00 has been released to address this. I added a few things
that put more power under the hood.
There's a --regex (or -r) option to enable PCREs. You could solve your
problem above by specifying -i "\Wgeorge\W" to break the word on non-word
characters (anything other than A-Za-z0-9_ would count as a \W, for those
who don't know). You could also differentiate between things like "pier1"
through "pier9", substituting "allpiers" into any of them but
"pier2" like so: -i "\Wpier[^2]\W" -o "allpiers"
Basically, full PCRE patterns are supported for pattern matching. Use as
much line noise as you like. :)
However, as a note, back-references are -not- currently usable in
substitution patterns. If you don't know what a back-reference is, you
can safely skip the rest of this paragraph. I've tried making them work,
and it flat-out doesn't/can't work due to a lack of double-interpolation
in perl. It's apparently not possible to make back-references work based
on user input, according to the docs. Since the substitution pattern
itself is interpolated to put it in play, the back-references will not be
interpolated. I don't see a way around that limitation of perl, or I'd
have implemented it.
Moving on... Because PCREs are extremely powerful, but can be twitchy,
I've added two safeguards, one of which is a nice feature even for
non-regex use.
One safeguard is a pattern display and confirmation. If you use --regex,
you're shown your patterns as perl sees them, and you're asked to confirm
to continue, or tell it to stop cold without doing anything. This can be
skipped by --expert, but I don't necessarily recommend it for all but the
most seasoned PCRE users.
The other safeguard is a nice new feature suggested by Ken Cole, called
--dry-run. This creates the backup directory and the LOGFILE.txt within,
and shows everything that would happen if you didn't use the option--but
it prevents any backups from being created, and prevents any files from
actually being changed. This allows you to see what would happen if you
ran the program, without having to revert from a bad set of patterns. You
can look at a dry run log and see if everything would be as intended.
If so, you can just run it without the option to actually perform the
substitutions. I also made the directories containing the logfiles
suffixed by _DRYRUN, so you can instantly see which were real runs and
which were dry runs. It's noted in the logfile itself, but I thought the
instant clue in the filename would be helpful. Many thanks to Ken for
suggesting dry runs as a feature!
The new version is up, the docs have been updated, and it's now much more
powerful than the original. My thanks to everyone who gave feedback!
Bests,
mark->
--
Fairlight Consulting
http://www.fairlite.com
fairlite at fairlite.com
(502) 509-3840
More information about the Filepro-list
mailing list