Scripted Find-Replace (suggestion)

Ideas for new features

Moderators: AmigoJack, bbadmin, helios, Bob Hansen, MudGuard

Post Reply
User avatar
trids
Posts: 69
Joined: Wed May 07, 2003 10:16 am
Location: South Africa

Scripted Find-Replace (suggestion)

Post by trids »

I would like to see a way to script multiple find-replace operations with TextPad's Regular Expressions (RE) engine. Macros are still un-editable and therefore not a viable solution.

My current solution for this is to use the GnuWIN sed.exe commandline utility, which works like a dream but has the following shortcomings:
  • The sed RE syntax is slightly different from TP's .. especially in the way that it handles line breaks (\n). TP's syntax is much easier!
  • If I want to share my RE scripts with colleagues who already use TP, I have to install sed on their machines too, and highlight the differences with TP's REs.
Suggestion: Provide a commandline exe with the TP installation that can be used like sed, but which interfaces with TextPad.exe to use RE syntax consistent with TP's. It would be very helpful if this utility could also honour sed-like comments for the RE script. See example below.

Example-1
using sed to convert pipe(|) delimiters to tabs for pasting into MS-Excel.

Code: Select all

  sed "s/^| *//;s/ *| */\t/g"  D:\_isqlout1.txt

Example-2
As above, but using a script-file with comments to describe each step.

Code: Select all

  sed -f D:\sed\pipes_to_tabs.sed  D:\_isqlout1.txt
where D:\sed\pipes_to_tabs.sed contains the following:

Code: Select all

s/^| *//         # drop leading pipe
s/ *| */\t/g     # replace all other pipes. "g" (global) means "don't stop after first replacement"
Quick tip: the sed syntax is "s/_find_/_replace_/" .. where "s" means "substitute".

Here's a thought. This kind of commandline utility that interfaces with the TextPad.exe might also provide the answer to the demand for editable macros! The editable script file in this case would simply specify the keystrokes ;) .. and cleverly sidesteps the temptation to invent a yet another new macro language.

HTH
Zhiroc
Posts: 7
Joined: Sat Aug 11, 2007 5:40 pm

Post by Zhiroc »

I just had a thought: how about an imbedded Perl interpreter as a macro language? Seems like the perfect language for such a task.
User avatar
trids
Posts: 69
Joined: Wed May 07, 2003 10:16 am
Location: South Africa

Post by trids »

Rather than a whole new scripting language, I would prefer to have an API that I can use with my own choice of scripting language :wink:

My personal preference for a scripting language is AutoIt 3, by the way. But people could use VB script or PERL or whatever -- if only they had a set of function-calls to interface with the TP engine.

However, that's a bit outside the scope of this thread, which is aimed at suggesting a commandline interface to TP's regexps.

I probably shouldn't have mentioned editable macros, but it occurred to me that an editable list of keypresses might be submitted to TP using the same commandline vehicle that I'm suggesting for REs.

:idea: So Helios .. any hope of a commandline RE interface :?:
Post Reply